Files
hanzo.ai/components/shell/prompt.ts

34 lines
889 B
TypeScript

import { CHAT } from '@/components/home/nav-data'
/**
* What a visitor typed, held across the trip to Hanzo IAM.
*
* sessionStorage, so it dies with the tab and never rides a URL past the
* issuer. Read once: the composer takes it the moment there is a session.
*/
const KEY = 'hz_prompt'
export function keep(text: string): void {
try {
window.sessionStorage.setItem(KEY, text)
} catch {
/* private mode — the visitor lands in chat with an empty field */
}
}
export function take(): string {
try {
const text = window.sessionStorage.getItem(KEY) ?? ''
window.sessionStorage.removeItem(KEY)
return text
} catch {
return ''
}
}
/** Chat reads its opening line off `q` — the name every Hanzo chat takes. */
export const chat = (prompt: string): string => {
const q = prompt.trim()
return q ? `${CHAT}?q=${encodeURIComponent(q)}` : CHAT
}