diff --git a/src/data/voice_assistant.ts b/src/data/voice_assistant.ts index eb2805f5bf..a1aa203d54 100644 --- a/src/data/voice_assistant.ts +++ b/src/data/voice_assistant.ts @@ -119,8 +119,6 @@ export const runPipelineFromText = ( return; } - run.events.push(updateEvent); - if (updateEvent.type === "stt-start") { run = { ...run, stage: "stt", stt: updateEvent.data }; } else if (updateEvent.type === "stt-finish") { @@ -139,8 +137,12 @@ export const runPipelineFromText = ( } else if (updateEvent.type === "error") { run = { ...run, stage: "error", error: updateEvent.data }; unsubProm.then((unsub) => unsub()); + } else { + run = { ...run }; } + run.events = [...run.events, updateEvent]; + callback(run); }, { diff --git a/src/panels/config/integrations/integration-panels/voice_assistant/assist/assist-pipeline-debug.ts b/src/panels/config/integrations/integration-panels/voice_assistant/assist/assist-pipeline-debug.ts index bb63e084a5..bfff3a544d 100644 --- a/src/panels/config/integrations/integration-panels/voice_assistant/assist/assist-pipeline-debug.ts +++ b/src/panels/config/integrations/integration-panels/voice_assistant/assist/assist-pipeline-debug.ts @@ -2,6 +2,8 @@ import { css, html, LitElement, TemplateResult } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import "../../../../../../components/ha-card"; import "../../../../../../components/ha-button"; +import "../../../../../../components/ha-circular-progress"; +import "../../../../../../components/ha-expansion-panel"; import "../../../../../../components/ha-textfield"; import { PipelineRun, @@ -12,6 +14,58 @@ import { SubscribeMixin } from "../../../../../../mixins/subscribe-mixin"; import { haStyle } from "../../../../../../resources/styles"; import { HomeAssistant } from "../../../../../../types"; +const RUN_DATA = { + pipeline: "Pipeline", + language: "Language", +}; + +const ERROR_DATA = { + code: "Code", + message: "Message", +}; + +const INTENT_DATA = { + engine: "Engine", + intent_input: "Input", +}; + +const renderProgress = ( + pipelineRun: PipelineRun, + stage: PipelineRun["stage"] +) => + pipelineRun.stage !== stage && stage in pipelineRun + ? html`✅` + : pipelineRun.stage === stage + ? html`` + : ""; + +const renderData = (data: Record, keys: Record) => + Object.entries(keys).map( + ([key, label]) => + html` +
+
${label}
+
${data[key]}
+
+ ` + ); + +const dataMinusKeysRender = ( + data: Record, + keys: Record +) => { + const result = {}; + let render = false; + for (const key in data) { + if (key in keys) { + continue; + } + render = true; + result[key] = data[key]; + } + return render ? html`
${JSON.stringify(result, null, 2)}
` : ""; +}; + @customElement("assist-pipeline-debug") export class AssistPipelineDebug extends SubscribeMixin(LitElement) { @property({ attribute: false }) public hass!: HomeAssistant; @@ -52,11 +106,44 @@ export class AssistPipelineDebug extends SubscribeMixin(LitElement) { ${this._pipelineRun ? html` - +
-
${JSON.stringify(this._pipelineRun, null, 2)}
+
+
Run
+
${this._pipelineRun.stage}
+
+ + ${renderData(this._pipelineRun.run, RUN_DATA)} + ${this._pipelineRun.error + ? renderData(this._pipelineRun.error, ERROR_DATA) + : ""}
+ +
+
+ Natural Language Processing + ${renderProgress(this._pipelineRun, "intent")} +
+ ${this._pipelineRun.intent + ? html` +
+ ${renderData(this._pipelineRun.intent, INTENT_DATA)} + ${dataMinusKeysRender( + this._pipelineRun.intent, + INTENT_DATA + )} +
+ ` + : ""} +
+
+ + + Raw +
${JSON.stringify(this._pipelineRun, null, 2)}
+
+
` : ""} @@ -92,9 +179,19 @@ export class AssistPipelineDebug extends SubscribeMixin(LitElement) { .run-pipeline-card ha-textfield { display: block; } + .row { + display: flex; + justify-content: space-between; + } pre { margin: 0; } + ha-expansion-panel { + padding-left: 8px; + } + .heading { + font-weight: 500; + } `, ]; }