47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { resolveThemeFromQuery } from "@/core/auth/external-login";
|
|
|
|
const DEFAULT_USERNAME = "guest";
|
|
|
|
export type EmbedChatParams = {
|
|
/** Parent correlation id — required for status polling without thread_id. */
|
|
sessionId: string;
|
|
message: string;
|
|
username: string;
|
|
theme: string;
|
|
};
|
|
|
|
/**
|
|
* Resolve iframe embed params from URL query only (plain iframe, not wujie).
|
|
*
|
|
* Parent must generate ``sessionId`` and pass it on the iframe URL so it can
|
|
* poll ``GET /api/public/embed/sessions/{sessionId}/status`` without reading
|
|
* the child frame.
|
|
*/
|
|
export function resolveEmbedChatParams(search: string): EmbedChatParams {
|
|
const params = new URLSearchParams(search.startsWith("?") ? search : `?${search}`);
|
|
|
|
const sessionId =
|
|
params.get("sessionId")?.trim() ||
|
|
params.get("session_id")?.trim() ||
|
|
"";
|
|
|
|
const message =
|
|
params.get("message")?.trim() ||
|
|
params.get("question")?.trim() ||
|
|
params.get("text")?.trim() ||
|
|
"";
|
|
|
|
const username =
|
|
params.get("username")?.trim() ||
|
|
params.get("userName")?.trim() ||
|
|
DEFAULT_USERNAME;
|
|
|
|
const theme = params.get("theme")?.trim() || "";
|
|
|
|
return { sessionId, message, username, theme };
|
|
}
|
|
|
|
export function resolveEmbedTheme(themeParam: string): "dark" | "light" {
|
|
return resolveThemeFromQuery(themeParam || null);
|
|
}
|