Open History to see the last commit
1export function previewUrlFromText(text: string): string | null {
2 const match = text.match(/https?:\/\/[^\s)"']+/)
3 return match ? match[0] : null
4}
5
6export function previewUrlFrom(output: unknown): string | null {
7 let value: unknown = output
8 if (typeof output === 'string') {
9 try {
10 value = JSON.parse(output)
11 } catch {
12 return /^https?:\/\//.test(output) ? output : null
13 }
14 }
15 if (value !== null && typeof value === 'object' && 'url' in value) {
16 const url = value.url
17 return typeof url === 'string' ? url : null
18 }
19 return null
20}
21
22export const DEFAULT_COMPARE_PROMPT =
23 'Keep the same product. Change only the visual direction.'
24
25export function comparePrompt(userText: string): string {
26 const trimmed = userText.trim()
27 return trimmed.length > 0 ? trimmed : DEFAULT_COMPARE_PROMPT
28}
29
30export function variantPrompt(userText: string, variant: 'A' | 'B'): string {
31 const prompt = comparePrompt(userText)
32 if (variant === 'A') {
33 return `${prompt}\n\nThis is variant A. Keep the same product. Use a bold, high-contrast, compact visual direction.`
34 }
35 return `${prompt}\n\nThis is variant B. Keep the same product. Use a soft, spacious, calm visual direction.`
36}
37
38export function threadIdsFromForkBody(body: unknown): Array<string> {
39 if (body === null || typeof body !== 'object') return []
40 const forks = Reflect.get(body, 'forks')
41 if (!Array.isArray(forks)) return []
42 return forks.flatMap((fork) => {
43 if (fork === null || typeof fork !== 'object') return []
44 const id = Reflect.get(fork, 'threadId')
45 return typeof id === 'string' && id.length > 0 ? [id] : []
46 })
47}
48
49export function errorMessageFromBody(body: unknown, fallback: string): string {
50 if (body !== null && typeof body === 'object' && 'error' in body) {
51 const error = body.error
52 if (typeof error === 'string' && error.length > 0) return error
53 }
54 return fallback
55}