Skip to content

Bug: VoiceTool unsafe 'as string' casts on untyped voiceSpeak response #3197

@mrveiss

Description

@mrveiss

Context

Discovered during code review of #3167 (PR #3180). Pre-existing issue not introduced by that PR.

Problem

In src/views/tools/admin/VoiceTool.vue line 168:

aiResponse.value = (response.response as string) || (response.text as string) || 'No response received'

api.voiceSpeak() returns Promise<Record<string, unknown>>. The as string casts are unsafe — if the property is actually an object, number, or undefined, the value will be [object Object], "0", or silently pass through to the fallback.

Solution

Use proper type narrowing:

const text = typeof response.response === 'string' ? response.response
  : typeof response.text === 'string' ? response.text
  : 'No response received'
aiResponse.value = text

Or define a proper VoiceSpeakResponse interface (related to #3196).

Files

  • src/views/tools/admin/VoiceTool.vue:168
  • src/composables/useAutobotApi.ts:587voiceSpeak return type

Discovered During

Code review of PR #3180 (implementation of #3167)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions