Skip to content

Commit f392d4e

Browse files
committed
add canonical agent-session control plane
1 parent 552ee29 commit f392d4e

126 files changed

Lines changed: 19640 additions & 2857 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Tiltfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ load("ext://restart_process", "docker_build_with_restart")
2020
load("ext://secret", "secret_create_generic")
2121
load('ext://dotenv', 'dotenv')
2222

23+
update_settings(k8s_upsert_timeout_secs=180)
24+
2325
# Load .env file if it exists
2426
dotenv()
2527

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Copyright 2026 GoodRx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { NextRequest } from 'next/server';
18+
19+
jest.mock('server/lib/get-user', () => ({
20+
getRequestUserIdentity: jest.fn(),
21+
}));
22+
23+
jest.mock('server/services/agent/AdminService', () => ({
24+
__esModule: true,
25+
default: {
26+
getThreadConversation: jest.fn(),
27+
},
28+
}));
29+
30+
import { GET } from './route';
31+
import { getRequestUserIdentity } from 'server/lib/get-user';
32+
import AgentAdminService from 'server/services/agent/AdminService';
33+
34+
const mockGetRequestUserIdentity = getRequestUserIdentity as jest.Mock;
35+
const mockGetThreadConversation = AgentAdminService.getThreadConversation as jest.Mock;
36+
37+
function makeRequest(): NextRequest {
38+
return {
39+
headers: new Headers([['x-request-id', 'req-test']]),
40+
nextUrl: new URL('http://localhost/api/v2/ai/admin/agent/threads/thread-1/conversation'),
41+
} as unknown as NextRequest;
42+
}
43+
44+
describe('GET /api/v2/ai/admin/agent/threads/[threadId]/conversation', () => {
45+
beforeEach(() => {
46+
jest.clearAllMocks();
47+
});
48+
49+
it('returns 401 when the requester is not authenticated', async () => {
50+
mockGetRequestUserIdentity.mockReturnValue(null);
51+
52+
const response = await GET(makeRequest(), { params: { threadId: 'thread-1' } });
53+
54+
expect(response.status).toBe(401);
55+
await expect(response.json()).resolves.toMatchObject({
56+
error: { message: 'Unauthorized' },
57+
});
58+
expect(mockGetThreadConversation).not.toHaveBeenCalled();
59+
});
60+
61+
it('returns the canonical admin replay payload from the service', async () => {
62+
mockGetRequestUserIdentity.mockReturnValue({
63+
userId: 'sample-admin',
64+
githubUsername: 'sample-admin',
65+
});
66+
mockGetThreadConversation.mockResolvedValue({
67+
session: { id: 'session-1' },
68+
thread: { id: 'thread-1' },
69+
messages: [
70+
{
71+
id: 'message-1',
72+
role: 'user',
73+
parts: [{ type: 'text', text: 'Hi' }],
74+
},
75+
],
76+
runs: [],
77+
events: [],
78+
pendingActions: [],
79+
toolExecutions: [
80+
{
81+
id: 'tool-1',
82+
toolCallId: 'tool-call-1',
83+
},
84+
],
85+
});
86+
87+
const response = await GET(makeRequest(), { params: { threadId: 'thread-1' } });
88+
const body = await response.json();
89+
90+
expect(response.status).toBe(200);
91+
expect(mockGetThreadConversation).toHaveBeenCalledWith('thread-1');
92+
expect(body.data.messages[0]).toEqual({
93+
id: 'message-1',
94+
role: 'user',
95+
parts: [{ type: 'text', text: 'Hi' }],
96+
});
97+
expect(body.data.toolExecutions[0]).toEqual({
98+
id: 'tool-1',
99+
toolCallId: 'tool-call-1',
100+
});
101+
});
102+
103+
it.each(['Agent thread not found', 'Agent session not found'])('returns 404 for %s', async (message) => {
104+
mockGetRequestUserIdentity.mockReturnValue({
105+
userId: 'sample-admin',
106+
githubUsername: 'sample-admin',
107+
});
108+
mockGetThreadConversation.mockRejectedValue(new Error(message));
109+
110+
const response = await GET(makeRequest(), { params: { threadId: 'missing-thread' } });
111+
112+
expect(response.status).toBe(404);
113+
await expect(response.json()).resolves.toMatchObject({
114+
error: { message },
115+
});
116+
});
117+
});

‎src/app/api/v2/ai/admin/agent/threads/[threadId]/conversation/route.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import AgentAdminService from 'server/services/agent/AdminService';
2626
* get:
2727
* summary: Get full agent thread conversation for admin review
2828
* description: >
29-
* Returns the persisted UI messages for a thread together with runs,
30-
* pending actions, and tool executions so admins can replay the session.
29+
* Returns the canonical messages for a thread together with runs, run
30+
* events, pending actions, and tool executions so admins can replay the session.
3131
* tags:
3232
* - Agent Admin
3333
* operationId: getAdminAgentThreadConversation

0 commit comments

Comments
 (0)