agents: add sse scaffolding

This commit is contained in:
ramnique 2025-03-24 11:57:22 +05:30 committed by Ramnique Singh
parent e725fc6276
commit b131c1768e
6 changed files with 64 additions and 8 deletions

View file

@ -66,17 +66,14 @@ export async function scrapeWebpage(url: string): Promise<z.infer<typeof Webpage
};
}
export async function getAssistantResponse(
projectId: string,
request: z.infer<typeof AgenticAPIChatRequest>,
): Promise<{
export async function getAssistantResponse(request: z.infer<typeof AgenticAPIChatRequest>): Promise<{
messages: z.infer<typeof apiV1.ChatMessage>[],
state: unknown,
rawRequest: unknown,
rawResponse: unknown,
}> {
await projectAuthCheck(projectId);
if (!await check_query_limit(projectId)) {
await projectAuthCheck(request.projectId);
if (!await check_query_limit(request.projectId)) {
throw new QueryLimitError();
}

View file

@ -88,6 +88,7 @@ export async function POST(
// get assistant response
const { agents, tools, prompts, startAgent } = convertWorkflowToAgenticAPI(workflow);
const request: z.infer<typeof AgenticAPIChatRequest> = {
projectId,
messages: convertFromApiToAgenticApiMessages(reqMessages),
state: currentState,
agents,

View file

@ -95,6 +95,7 @@ export async function POST(
let state: unknown = chat.agenticState ?? { last_agent_name: startAgent };
const request: z.infer<typeof AgenticAPIChatRequest> = {
projectId: session.projectId,
messages: convertToAgenticAPIChatMessages([systemMessage, ...messages, ...unsavedMessages]),
state,
agents,

View file

@ -47,6 +47,7 @@ export const AgenticAPITool = WorkflowTool
})
export const AgenticAPIChatRequest = z.object({
projectId: z.string(),
messages: z.array(AgenticAPIChatMessage),
state: z.unknown(),
agents: z.array(AgenticAPIAgent),

View file

@ -96,6 +96,7 @@ export function Chat({
setFetchResponseError(null);
const { agents, tools, prompts, startAgent } = convertWorkflowToAgenticAPI(workflow);
const request: z.infer<typeof AgenticAPIChatRequest> = {
projectId,
messages: convertToAgenticAPIChatMessages([{
role: 'system',
content: systemMessage || '',
@ -116,7 +117,7 @@ export function Chat({
setLastAgenticResponse(null);
try {
const response = await getAssistantResponse(projectId, request);
const response = await getAssistantResponse(request);
if (ignore) {
return;
}