Skip to content

Commit 4996bf8

Browse files
committed
Add endpoint to fetch session messages and update frontend handling
- Implemented a new API endpoint to retrieve messages for a specific session, enhancing data retrieval from the content service. - Updated the ProjectSessionDetailPage to fetch and display messages, ensuring real-time updates and improved user experience. - Modified the AgenticSessionStatus type to include message count, aligning with the new message handling logic.
1 parent ca1fda4 commit 4996bf8

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

components/backend/handlers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,22 @@ func getSession(c *gin.Context) {
806806
c.JSON(http.StatusOK, session)
807807
}
808808

809+
// GET /api/projects/:projectName/agentic-sessions/:sessionName/messages
810+
// Returns the messages.json content for a session by fetching from the per-project content service
811+
// and falling back to local state directory if the content service is unavailable.
812+
func getSessionMessages(c *gin.Context) {
813+
project := c.GetString("project")
814+
sessionName := c.Param("sessionName")
815+
816+
// First try via per-namespace content service using caller's token
817+
data, err := readProjectContentFile(c, project, fmt.Sprintf("/sessions/%s/messages.json", sessionName))
818+
if err != nil {
819+
c.JSON(http.StatusBadGateway, gin.H{"error": "failed to fetch messages"})
820+
return
821+
}
822+
c.Data(http.StatusOK, "application/json", data)
823+
}
824+
809825
// --- Git helpers (project-scoped) ---
810826

811827
func stringPtr(s string) *string { return &s }

components/backend/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func main() {
101101
projectGroup.POST("/agentic-sessions/:sessionName/stop", stopSession)
102102
projectGroup.PUT("/agentic-sessions/:sessionName/status", updateSessionStatus)
103103
projectGroup.PUT("/agentic-sessions/:sessionName/displayname", updateSessionDisplayName)
104+
projectGroup.GET("/agentic-sessions/:sessionName/messages", getSessionMessages)
104105

105106
// RFE workflow endpoints (project-scoped)
106107
projectGroup.GET("/rfe-workflows", listProjectRFEWorkflows)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { BACKEND_URL } from '@/lib/config'
2+
import { buildForwardHeadersAsync } from '@/lib/auth'
3+
4+
export async function GET(
5+
request: Request,
6+
{ params }: { params: Promise<{ name: string; sessionName: string }> },
7+
) {
8+
const { name, sessionName } = await params
9+
const headers = await buildForwardHeadersAsync(request)
10+
const resp = await fetch(`${BACKEND_URL}/projects/${encodeURIComponent(name)}/agentic-sessions/${encodeURIComponent(sessionName)}/messages`, { headers })
11+
const contentType = resp.headers.get('content-type') || 'application/json'
12+
const body = await resp.text()
13+
return new Response(body, { status: resp.status, headers: { 'Content-Type': contentType } })
14+
}
15+
16+

components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export default function ProjectSessionDetailPage({ params }: { params: Promise<{
121121
const [sessionName, setSessionName] = useState<string>("");
122122

123123
const [session, setSession] = useState<AgenticSession | null>(null);
124+
const [messages, setMessages] = useState<MessageObject[]>([]);
124125
const [loading, setLoading] = useState(true);
125126
const [error, setError] = useState<string | null>(null);
126127
const [actionLoading, setActionLoading] = useState<string | null>(null);
@@ -151,6 +152,14 @@ export default function ProjectSessionDetailPage({ params }: { params: Promise<{
151152
}
152153
const data = await response.json();
153154
setSession(data);
155+
// Fetch messages from proxy endpoint to ensure latest content
156+
const msgResp = await fetch(
157+
`${apiUrl}/projects/${encodeURIComponent(projectName)}/sessions/${encodeURIComponent(sessionName)}/messages`
158+
);
159+
if (msgResp.ok) {
160+
const msgData = await msgResp.json();
161+
if (Array.isArray(msgData)) setMessages(msgData);
162+
}
154163
} catch (err) {
155164
setError(err instanceof Error ? err.message : "Unknown error");
156165
} finally {
@@ -522,7 +531,7 @@ export default function ProjectSessionDetailPage({ params }: { params: Promise<{
522531
)}
523532

524533
{/* Real-time Messages Progress*/}
525-
{((session.status?.messages && session.status.messages.length > 0) ||
534+
{(messages.length > 0 ||
526535
session.status?.phase === "Running" ||
527536
session.status?.phase === "Pending" ||
528537
session.status?.phase === "Creating") && (
@@ -531,16 +540,16 @@ export default function ProjectSessionDetailPage({ params }: { params: Promise<{
531540
<CardTitle className="flex items-center justify-between">
532541
<span>Agentic Progress</span>
533542
<Badge variant="secondary">
534-
{mergeToolUseAndResults(session.status?.messages).length} message
535-
{mergeToolUseAndResults(session.status?.messages).length !== 1 ? "s" : ""}
543+
{mergeToolUseAndResults(messages).length} message
544+
{mergeToolUseAndResults(messages).length !== 1 ? "s" : ""}
536545
</Badge>
537546
</CardTitle>
538547
<CardDescription>Live analysis from Claude AI</CardDescription>
539548
</CardHeader>
540549
<CardContent>
541550
<div className="max-h-96 overflow-y-auto space-y-4 bg-gray-50 rounded-lg p-4">
542551
{/* Display all existing messages (normalized/merged) */}
543-
{mergeToolUseAndResults(session.status?.messages).map((message, index) => (
552+
{mergeToolUseAndResults(messages).map((message, index) => (
544553
<StreamMessage key={`msg-${index}`} message={message as any} />
545554
))}
546555

@@ -563,7 +572,7 @@ export default function ProjectSessionDetailPage({ params }: { params: Promise<{
563572
)}
564573

565574
{/* Show empty state if no messages yet */}
566-
{(!session.status?.messages || session.status.messages.length === 0) &&
575+
{(messages.length === 0) &&
567576
session.status?.phase !== "Running" &&
568577
session.status?.phase !== "Pending" &&
569578
session.status?.phase !== "Creating" && (

components/frontend/src/types/agentic-session.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ export type AgenticSessionStatus = {
106106
jobName?: string;
107107
finalOutput?: string;
108108
cost?: number;
109-
messages?: MessageObject[];
109+
// Storage & counts (align with CRD)
110+
stateDir?: string;
111+
artifactsCount?: number;
112+
messagesCount?: number;
110113
// Runner result summary fields
111114
subtype?: string;
112115
duration_ms?: number;

0 commit comments

Comments
 (0)