* Remove CLI from project * Simplify agent approvals to bash safety only * simplify agent cloud execution model * hardcode bash safety policy * Remove agent context compaction * remove * updates * refactor(agent): replace call options with agent factories * refactor(agent): remove prepareCall from agents * Use model selections in agent factory * Relax bash approval heuristics * Remove local and in-memory sandboxes * Refactor agent sandbox config to be serializable * Fix stale bash approval test * Revert "refactor(agent): replace call options with agent factories" This reverts commit b0b8345526b2dd152fe09b0ef25bd5b868290345. * refactor(agent): remove live sandbox from call options * refactor(agent): remove live sandbox compatibility path * refactor: extract chat auth context into reusable module (#444) Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com> * resolve merge conficts * soft reconnect fix * remove dead compaction context code from chat request helpers
63 lines
1.2 KiB
TypeScript
63 lines
1.2 KiB
TypeScript
import type { WebAgentUIMessage } from "@/app/types";
|
|
|
|
export interface ChatRequestBody {
|
|
messages: WebAgentUIMessage[];
|
|
sessionId?: string;
|
|
chatId?: string;
|
|
}
|
|
|
|
type ParseChatRequestResult =
|
|
| {
|
|
ok: true;
|
|
body: ChatRequestBody;
|
|
}
|
|
| {
|
|
ok: false;
|
|
response: Response;
|
|
};
|
|
|
|
type RequireChatIdentifiersResult =
|
|
| {
|
|
ok: true;
|
|
sessionId: string;
|
|
chatId: string;
|
|
}
|
|
| {
|
|
ok: false;
|
|
response: Response;
|
|
};
|
|
|
|
export async function parseChatRequestBody(
|
|
req: Request,
|
|
): Promise<ParseChatRequestResult> {
|
|
try {
|
|
const body = (await req.json()) as ChatRequestBody;
|
|
return { ok: true, body };
|
|
} catch {
|
|
return {
|
|
ok: false,
|
|
response: Response.json({ error: "Invalid JSON body" }, { status: 400 }),
|
|
};
|
|
}
|
|
}
|
|
|
|
export function requireChatIdentifiers(
|
|
body: ChatRequestBody,
|
|
): RequireChatIdentifiersResult {
|
|
if (!body.sessionId || !body.chatId) {
|
|
return {
|
|
ok: false,
|
|
response: Response.json(
|
|
{ error: "sessionId and chatId are required" },
|
|
{ status: 400 },
|
|
),
|
|
};
|
|
}
|
|
|
|
return {
|
|
ok: true,
|
|
sessionId: body.sessionId,
|
|
chatId: body.chatId,
|
|
};
|
|
}
|