feat: Enhance session management with prompt tracking
- Added prompt_number to observations and session summaries for better tracking. - Implemented prompt counter in SDK sessions to manage user prompts effectively. - Updated database schema to include prompt tracking columns and removed unique constraints on session summaries. - Modified hooks to utilize prompt_number in observations and summaries. - Changed worker service to handle summarize requests instead of finalize, keeping the SDK agent active. - Improved logging for better debugging and tracking of prompt numbers across sessions.
This commit is contained in:
@@ -42,10 +42,10 @@ export function contextHook(input?: SessionStartInput): void {
|
||||
output.push('');
|
||||
|
||||
// Group observations by type
|
||||
const byType: Record<string, Array<{text: string; created_at: string}>> = {};
|
||||
const byType: Record<string, Array<{text: string; prompt_number: number | null; created_at: string}>> = {};
|
||||
for (const obs of observations) {
|
||||
if (!byType[obs.type]) byType[obs.type] = [];
|
||||
byType[obs.type].push({ text: obs.text, created_at: obs.created_at });
|
||||
byType[obs.type].push({ text: obs.text, prompt_number: obs.prompt_number, created_at: obs.created_at });
|
||||
}
|
||||
|
||||
// Display each type
|
||||
@@ -54,7 +54,8 @@ export function contextHook(input?: SessionStartInput): void {
|
||||
if (byType[type] && byType[type].length > 0) {
|
||||
output.push(`### ${type.charAt(0).toUpperCase() + type.slice(1)}s`);
|
||||
for (const obs of byType[type]) {
|
||||
output.push(`- ${obs.text}`);
|
||||
const promptLabel = obs.prompt_number ? ` (prompt #${obs.prompt_number})` : '';
|
||||
output.push(`- ${obs.text}${promptLabel}`);
|
||||
}
|
||||
output.push('');
|
||||
}
|
||||
@@ -76,6 +77,10 @@ export function contextHook(input?: SessionStartInput): void {
|
||||
output.push('---');
|
||||
output.push('');
|
||||
|
||||
const promptLabel = summary.prompt_number ? ` (Prompt #${summary.prompt_number})` : '';
|
||||
output.push(`**Summary${promptLabel}**`);
|
||||
output.push('');
|
||||
|
||||
if (summary.request) {
|
||||
output.push(`**Request:** ${summary.request}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user