MCPcopy Create free account
hub / github.com/Noumena-Network/code / generateSessionTitle

Function generateSessionTitle

src/utils/sessionTitle.ts:81–139  ·  view source on GitHub ↗
(
  description: string,
  signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

79 * @param signal - Abort signal for cancellation
80 */
81export async function generateSessionTitle(
82 description: string,
83 signal: AbortSignal,
84): Promise<string | null> {
85 const trimmed = description.trim()
86 if (!trimmed) return null
87
88 // Avoid a duplicate background API error on first prompt when the user
89 // is not logged in. The main turn submission already surfaces the auth
90 // failure; title generation should quietly skip in that state.
91 if (getAPIProvider() === 'firstParty' && getAuthHeaders().error) {
92 return null
93 }
94
95 try {
96 const result = await queryHaiku({
97 systemPrompt: asSystemPrompt([SESSION_TITLE_PROMPT]),
98 userPrompt: trimmed,
99 outputFormat: {
100 type: 'json_schema',
101 schema: {
102 type: 'object',
103 properties: {
104 title: { type: 'string' },
105 },
106 required: ['title'],
107 additionalProperties: false,
108 },
109 },
110 signal,
111 options: {
112 querySource: 'generate_session_title',
113 agents: [],
114 // Reflect the actual session mode — this module is called from
115 // both the SDK print path (non-interactive) and the CCR remote
116 // session path via useRemoteSession (interactive).
117 isNonInteractiveSession: getIsNonInteractiveSession(),
118 hasAppendSystemPrompt: false,
119 mcpTools: [],
120 },
121 })
122
123 const text = extractTextContent(result.message.content)
124 const parsed = titleSchema().safeParse(
125 text.trim().startsWith('{') ? safeParseJSON(text, false) : null,
126 )
127 const title = parsed.success ? parsed.data.title.trim() || null : null
128
129 logEvent('ncode_session_title_generated', { success: title !== null })
130
131 return title
132 } catch (error) {
133 logForDebugging(`generateSessionTitle failed: ${error}`, {
134 level: 'error',
135 })
136 logEvent('ncode_session_title_generated', { success: false })
137 return null
138 }

Callers 3

generateAndPatchFunction · 0.85
runHeadlessStreamingFunction · 0.85
useRemoteSessionFunction · 0.85

Calls 8

getAPIProviderFunction · 0.85
queryHaikuFunction · 0.85
asSystemPromptFunction · 0.85
extractTextContentFunction · 0.85
getAuthHeadersFunction · 0.70
logForDebuggingFunction · 0.70
logEventFunction · 0.50

Tested by

no test coverage detected