feat: wire code agent runs to tool mode
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { normalizeAgentRunToolMode } from './agent-run-gateway.mjs';
|
||||
|
||||
export function createPostAgentRunsHandler({ userAuth, agentRunGateway }) {
|
||||
return async function postAgentRuns(request, response) {
|
||||
try {
|
||||
const sessionId = String(request.body?.session_id ?? '').trim() || null;
|
||||
const requestId = String(request.body?.request_id ?? '').trim();
|
||||
const userMessage = request.body?.user_message ?? null;
|
||||
const rawToolMode = request.body?.tool_mode ?? request.body?.toolMode ?? 'chat';
|
||||
const taskType = String(request.body?.task_type ?? request.body?.taskType ?? '').trim() || null;
|
||||
if (!requestId) {
|
||||
response.status(400).json({ message: '缺少 request_id' });
|
||||
return;
|
||||
@@ -12,6 +16,15 @@ export function createPostAgentRunsHandler({ userAuth, agentRunGateway }) {
|
||||
response.status(400).json({ message: '缺少 user_message' });
|
||||
return;
|
||||
}
|
||||
let toolMode = 'chat';
|
||||
try {
|
||||
toolMode = normalizeAgentRunToolMode(rawToolMode);
|
||||
} catch (err) {
|
||||
response.status(400).json({
|
||||
message: err instanceof Error ? err.message : '不支持的 tool_mode',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (sessionId) {
|
||||
const owns = await userAuth.ownsSession(request.currentUser.id, sessionId);
|
||||
if (!owns) {
|
||||
@@ -23,6 +36,8 @@ export function createPostAgentRunsHandler({ userAuth, agentRunGateway }) {
|
||||
sessionId,
|
||||
requestId,
|
||||
userMessage,
|
||||
toolMode,
|
||||
taskType,
|
||||
});
|
||||
response.status(202).json({ run });
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user