( description: string, signal: AbortSignal, )
| 77 | * @param signal - Abort signal for cancellation |
| 78 | */ |
| 79 | export async function generateSessionTitle( |
| 80 | description: string, |
| 81 | signal: AbortSignal, |
| 82 | ): Promise<string | null> { |
| 83 | const trimmed = description.trim() |
| 84 | if (!trimmed) return null |
| 85 | |
| 86 | try { |
| 87 | const result = await queryHaiku({ |
| 88 | systemPrompt: asSystemPrompt([SESSION_TITLE_PROMPT]), |
| 89 | userPrompt: trimmed, |
| 90 | outputFormat: { |
| 91 | type: 'json_schema', |
| 92 | schema: { |
| 93 | type: 'object', |
| 94 | properties: { |
| 95 | title: { type: 'string' }, |
| 96 | }, |
| 97 | required: ['title'], |
| 98 | additionalProperties: false, |
| 99 | }, |
| 100 | }, |
| 101 | signal, |
| 102 | options: { |
| 103 | querySource: 'generate_session_title', |
| 104 | agents: [], |
| 105 | // Reflect the actual session mode — this module is called from |
| 106 | // both the SDK print path (non-interactive) and the CCR remote |
| 107 | // session path via useRemoteSession (interactive). |
| 108 | isNonInteractiveSession: getIsNonInteractiveSession(), |
| 109 | hasAppendSystemPrompt: false, |
| 110 | mcpTools: [], |
| 111 | }, |
| 112 | }) |
| 113 | |
| 114 | const text = extractTextContent(result.message.content) |
| 115 | |
| 116 | const parsed = titleSchema().safeParse(safeParseJSON(text)) |
| 117 | const title = parsed.success ? parsed.data.title.trim() || null : null |
| 118 | |
| 119 | logEvent('tengu_session_title_generated', { success: title !== null }) |
| 120 | |
| 121 | return title |
| 122 | } catch (error) { |
| 123 | logForDebugging(`generateSessionTitle failed: ${error}`, { |
| 124 | level: 'error', |
| 125 | }) |
| 126 | logEvent('tengu_session_title_generated', { success: false }) |
| 127 | return null |
| 128 | } |
| 129 | } |
| 130 |
no test coverage detected