MCPcopy Create free account
hub / github.com/apache/maka / sessionTitleSource

Function sessionTitleSource

packages/runtime/src/session-title.ts:8–25  ·  view source on GitHub ↗
(input: { text: string; displayText?: string })

Source from the content-addressed store, hash-verified

6export const SESSION_TITLE_GENERATION_TIMEOUT_MS = 15_000;
7
8export function sessionTitleSource(input: { text: string; displayText?: string }): string {
9 const raw = input.displayText ?? input.text;
10 const cleaned = (raw.match(/<user-message>([\s\S]*?)<\/user-message>/i)?.[1] ?? raw)
11 .replace(/<system-reminder>[\s\S]*?<\/system-reminder>/gi, '')
12 .trim();
13 const bytes = new TextEncoder().encode(cleaned);
14 if (bytes.length <= MAX_SOURCE_BYTES) return cleaned;
15 let end = MAX_SOURCE_BYTES;
16 const decoder = new TextDecoder('utf-8', { fatal: true });
17 while (end > 0) {
18 try {
19 return decoder.decode(bytes.subarray(0, end));
20 } catch {
21 end -= 1;
22 }
23 }
24 return '';
25}
26
27export function fallbackSessionTitle(sourceText: string): string | undefined {
28 const firstLine = sourceText

Callers 2

sendMessageMethod · 0.85

Calls 2

replaceMethod · 0.80
trimMethod · 0.45

Tested by

no test coverage detected