"""Reset the Lyria music generation context for a hard transition."""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from tool_context import ToolContext
logger = logging.getLogger(__name__)
TOOL_NAME = "reset_music_context"
TOOL_DESCRIPTION = (
"Reset the Lyria music generation context. Causes a hard transition "
"without stopping the stream. Useful after major config changes (e.g. "
"BPM or scale). Requires active music session."
)
TOOL_PARAMETERS = {
"type": "object",
"properties": {
"guild_id": {"type": "string", "description": "Discord server (guild) ID."},
},
"required": ["guild_id"],
}
[docs]
async def run(
guild_id: str,
ctx: "ToolContext | None" = None,
) -> str:
"""Request a context reset for the active Lyria stream."""
if ctx is None or not hasattr(ctx, "adapter") or ctx.adapter is None:
return "Error: Discord adapter (ctx.adapter) is required."
from tools._discord_helpers import get_discord_client
client = get_discord_client(ctx)
if isinstance(client, str):
return client
lyria = ctx.adapter.lyria_service
try:
guild_id_int = int(guild_id)
except (ValueError, TypeError):
return "Error: Invalid guild_id."
return await lyria.reset_context(guild_id_int)