iobroker.assistant 1.4.12 → 1.4.14

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/build/main.js CHANGED
@@ -3357,7 +3357,7 @@ class Assistant extends adapter_core_1.Adapter {
3357
3357
  return;
3358
3358
  }
3359
3359
  const shown = (0, media_1.historyText)(question, attachments.images.length, !!attachments.video);
3360
- this.log.info(`${heard ? 'Voice Q' : 'Q'} (${obj.command} from ${caller}): ${shown}${attachments.video ? ` (video ${attachments.video.adapter}/${attachments.video.path})` : ''}`);
3360
+ this.log.info(`${heard ? 'Voice Q' : 'Q'} (${obj.command} from ${caller}): ${shown}${attachments.video ? ` (video ${(0, media_1.videoLocation)(attachments.video)})` : ''}`);
3361
3361
  this.setStateAsync('text.request', { val: shown, ack: true }).catch(() => { });
3362
3362
  this.setQuerySource(source);
3363
3363
  try {
@@ -3489,7 +3489,7 @@ class Assistant extends adapter_core_1.Adapter {
3489
3489
  const kb = (base64) => Math.round((base64.length * 3) / 4 / 1024);
3490
3490
  const parts = [
3491
3491
  images.length ? `${images.length} picture(s), ${images.reduce((n, i) => n + kb(i.data), 0)} KB` : '',
3492
- video ? `video ${video.adapter}/${video.path}` : '',
3492
+ video ? `video ${(0, media_1.videoLocation)(video)}` : '',
3493
3493
  ].filter(Boolean);
3494
3494
  this.journal?.step({
3495
3495
  stage: 'request',
@@ -3593,6 +3593,20 @@ class Assistant extends adapter_core_1.Adapter {
3593
3593
  }
3594
3594
  return 'If the request was only a command to switch devices on or off or to set them to a value, and everything worked, answer with the control marker [[DONE]] alone (a short beep plays instead of a sentence). For questions, errors or when you have something to tell, answer normally.';
3595
3595
  }
3596
+ /**
3597
+ * System-prompt instruction to answer in the language of the question: the system prompt, the device names and
3598
+ * the time/weather lines are in the configured language, and the model followed them instead of the question.
3599
+ */
3600
+ languageHint() {
3601
+ const lang = String(this.config.voiceLanguage || this.language || 'en');
3602
+ if (lang === 'ru') {
3603
+ return 'Всегда отвечай на том языке, на котором задан вопрос, даже если эти инструкции, имена устройств или данные на другом языке.';
3604
+ }
3605
+ if (lang === 'de') {
3606
+ return 'Antworte immer in der Sprache, in der die Frage gestellt wurde, auch wenn diese Anweisungen, die Gerätenamen oder die Daten in einer anderen Sprache sind.';
3607
+ }
3608
+ return 'Always answer in the language the question was asked in, even if these instructions, the device names or the data are in another language.';
3609
+ }
3596
3610
  /**
3597
3611
  * Length instruction for a request that came in by voice: the answer is cut at `ttsMaxChars` before it is
3598
3612
  * spoken, so the model is asked to stay within it. Empty for text requests (chat, Telegram, scripts) and
@@ -3794,7 +3808,7 @@ class Assistant extends adapter_core_1.Adapter {
3794
3808
  const { images, video } = this.attachments();
3795
3809
  if (!question.trim() && video) {
3796
3810
  // A video without a question: nothing looks at videos yet
3797
- this.log.info(`Video from '${source}' (${video.adapter}/${video.path}) not looked at: not supported yet.`);
3811
+ this.log.info(`Video from '${source}' (${(0, media_1.videoLocation)(video)}) not looked at: not supported yet.`);
3798
3812
  this.journal?.note({ tier: 'none' });
3799
3813
  this.journal?.step({ stage: 'none', title: 'A video without a question: videos are not looked at yet' });
3800
3814
  return (0, media_1.videoNotSupportedText)(this.answerLanguage());
@@ -3916,7 +3930,7 @@ class Assistant extends adapter_core_1.Adapter {
3916
3930
  // Only ask the model to emit the follow-up marker when satellites can actually re-open the mic.
3917
3931
  const followUp = this.config.voiceEnabled ? this.followUpHint() : '';
3918
3932
  const done = this.doneHint();
3919
- const parts = [this.config.systemPrompt || '', followUp, done, mem, ctx].filter(Boolean);
3933
+ const parts = [this.config.systemPrompt || '', this.languageHint(), followUp, done, mem, ctx].filter(Boolean);
3920
3934
  const sys = parts.length ? parts.join('\n\n') : undefined;
3921
3935
  this.log.info(`Cloud LLM [${this.agent.model || 'auto'}] (source='${source}', context=${history.length} turn(s)${mem ? ', memory' : ''}${weather ? ', weather' : ''}${this.presence?.configured ? ', presence' : ''}) — running tool loop…`);
3922
3936
  // Prepend the current date/time (and the weather line, if a source is configured) to the user turn —
@@ -3949,7 +3963,7 @@ class Assistant extends adapter_core_1.Adapter {
3949
3963
  time,
3950
3964
  weather: weather || undefined,
3951
3965
  images: images.length || undefined,
3952
- video: video ? `${video.adapter}/${video.path}` : undefined,
3966
+ video: video ? (0, media_1.videoLocation)(video) : undefined,
3953
3967
  },
3954
3968
  });
3955
3969
  try {
@@ -3982,7 +3996,7 @@ class Assistant extends adapter_core_1.Adapter {
3982
3996
  const followUp = this.config.voiceEnabled ? this.followUpHint() : '';
3983
3997
  // The device list maps names to state ids, so pi-agent can act without searching first. It is the
3984
3998
  // first to go when the instructions get too long — pi-agent can still search.
3985
- const { text: instructions, dropped } = (0, piAgent_1.composeInstructions)([this.config.systemPrompt || '', followUp, this.doneHint(), this.spokenLengthHint()], [this.buildMemoryContext(), await this.buildDeviceContext()]);
3999
+ const { text: instructions, dropped } = (0, piAgent_1.composeInstructions)([this.config.systemPrompt || '', this.languageHint(), followUp, this.doneHint(), this.spokenLengthHint()], [this.buildMemoryContext(), await this.buildDeviceContext()]);
3986
4000
  if (dropped) {
3987
4001
  this.log.debug(`pi-agent: ${dropped} context block(s) left out, the instructions would be too long.`);
3988
4002
  }
@@ -4108,7 +4122,7 @@ class Assistant extends adapter_core_1.Adapter {
4108
4122
  continue; // hidden from the LLM
4109
4123
  }
4110
4124
  const room = d.room ? `${d.room}, ` : '';
4111
- lines.push(`- ${d.name} (${room}${d.type}): ${ids.join(', ')}`);
4125
+ lines.push(`- ${d.name} (${room}${d.type}): ${this.describeControls(d)}`);
4112
4126
  }
4113
4127
  const lang = String(this.config.voiceLanguage || this.language || 'en');
4114
4128
  lines.push(...this.satelliteVolumeLines(lang));
@@ -4116,12 +4130,35 @@ class Assistant extends adapter_core_1.Adapter {
4116
4130
  return '';
4117
4131
  }
4118
4132
  const header = lang === 'ru'
4119
- ? 'Известные устройства — «имя (комната, тип): stateId». Используй эти stateId напрямую с set_state/get_states; вызывай list_devices только если нужного устройства здесь нет.'
4133
+ ? 'Известные устройства — «имя (комната, тип): элемент stateId [вид]; …». Используй эти stateId напрямую с set_state/get_states; вызывай list_devices только если нужного устройства здесь нет. Если у устройства есть выключатель [on/off] и уровень [number], то «включи» — это выключатель = true (уровень — только если его назвали): один уровень устройство не включает.'
4120
4134
  : lang === 'de'
4121
- ? 'Bekannte Geräte — "Name (Raum, Typ): stateId". Nutze diese stateIds direkt mit set_state/get_states; rufe list_devices nur, wenn ein Gerät hier fehlt.'
4122
- : 'Known devices — "name (room, type): stateId". Use these stateIds directly with set_state/get_states; only call list_devices if a needed device is missing here.';
4135
+ ? 'Bekannte Geräte — "Name (Raum, Typ): Element stateId [Art]; …". Nutze diese stateIds direkt mit set_state/get_states; rufe list_devices nur, wenn ein Gerät hier fehlt. Hat ein Gerät einen Schalter [on/off] und einen Level [number], heißt "einschalten" Schalter = true (den Level nur, wenn er genannt wurde): der Level allein schaltet das Gerät nicht ein.'
4136
+ : 'Known devices — "name (room, type): element stateId [kind]; …". Use these stateIds directly with set_state/get_states; only call list_devices if a needed device is missing here. If a device has a switch [on/off] and a level [number], "turn on" means switch = true (the level only if one was asked for): the level alone does not switch the device on.';
4123
4137
  return `${header}\n${lines.join('\n')}`;
4124
4138
  }
4139
+ /**
4140
+ * The controls of a device for the LLM: element, state id and what it is. A bare list of ids did not tell the
4141
+ * level from the switch next to it, and the model set only the level of a light, so it stayed off.
4142
+ */
4143
+ describeControls(d) {
4144
+ const seen = new Set();
4145
+ const parts = [];
4146
+ for (const [key, id] of Object.entries(d.controls)) {
4147
+ if (seen.has(id)) {
4148
+ continue;
4149
+ }
4150
+ seen.add(id);
4151
+ const kind = d.writable[key] === false
4152
+ ? 'read-only'
4153
+ : d.types[key] === 'boolean'
4154
+ ? 'on/off'
4155
+ : d.types[key] === 'number'
4156
+ ? 'number'
4157
+ : '';
4158
+ parts.push(kind ? `${key} ${id} [${kind}]` : `${key} ${id}`);
4159
+ }
4160
+ return parts.join('; ');
4161
+ }
4125
4162
  /**
4126
4163
  * The playback volume of every voice satellite as a line of the device list. Without it, "Lautstärke auf 50
4127
4164
  * Prozent" that the rules miss reaches the LLM (or pi-agent) with only the media devices of the room in view, and