import { router } from '../../appRouter';
/**
* Resolves the active frontend route (path + search query).
* Falls back to window.location if router is not directly accessible.
* @returns {string} e.g. "/artikel" or "/artikel/ART-10042" or "/artikel?target=kabel"
*/
export function getCurrentRoute() {
if (typeof window !== 'undefined' && window.location) {
const { pathname = '/', search = '' } = window.location;
return `${pathname}${search}`;
}
return '/artikel';
}
/**
* Builds the ... XML prefix for LLM agent prompts.
* @param {string} [route]
* @returns {string}
*/
export function buildUserEnvPrefix(route) {
const resolvedRoute = route || getCurrentRoute();
return `${resolvedRoute}`;
}
export const USER_ENV_REGEX = /[\s\S]*?(?:<\/USERENV>|$)\s*/gi;
/**
* Strips ... tags from a message so it is not rendered in the chat view.
* @param {string} text
* @returns {string}
*/
export function stripUserEnv(text) {
if (typeof text !== 'string' || !text.includes('... block to the user prompt if not already present.
* @param {string} text
* @param {string} [route]
* @returns {string}
*/
export function attachUserEnv(text = '', route) {
const trimmed = typeof text === 'string' ? text.trim() : '';
if (trimmed.includes('