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