feat: add tool gateway protocol
This commit is contained in:
@@ -106,6 +106,7 @@ export function createAgentRunGateway({
|
||||
pool,
|
||||
userAuth,
|
||||
tkmindProxy,
|
||||
toolGateway = null,
|
||||
retryDelaysMs = DEFAULT_RUN_RETRY_DELAYS_MS,
|
||||
autoDispatch = envFlag(process.env.MEMIND_AGENT_RUN_AUTODISPATCH, true),
|
||||
maxConcurrentRuns = positiveInteger(
|
||||
@@ -251,6 +252,33 @@ export function createAgentRunGateway({
|
||||
async function executeRun(row, runId) {
|
||||
const userMessage = safeJsonParse(row.user_message_json, {});
|
||||
const runOptions = getRunOptionsFromMessage(userMessage);
|
||||
const toolGatewayStatus = toolGateway?.getStatus ? toolGateway.getStatus() : null;
|
||||
if (runOptions.toolMode === 'code' && toolGatewayStatus?.enabled) {
|
||||
const workingDir = userAuth?.resolveWorkingDir
|
||||
? await userAuth.resolveWorkingDir(row.user_id)
|
||||
: undefined;
|
||||
await appendEvent(runId, 'tool_gateway_dispatch', {
|
||||
protocol: toolGatewayStatus.protocol ?? 'agent-run-v1',
|
||||
taskType: runOptions.taskType,
|
||||
workingDir: workingDir ?? null,
|
||||
});
|
||||
const result = await toolGateway.executeJob({
|
||||
runId,
|
||||
userId: row.user_id,
|
||||
requestId: row.request_id,
|
||||
userMessage,
|
||||
taskType: runOptions.taskType,
|
||||
cwd: workingDir,
|
||||
timeoutMs: runTimeoutMs,
|
||||
});
|
||||
await appendEvent(runId, 'tool_gateway_result', {
|
||||
executor: result.executor ?? null,
|
||||
dryRun: Boolean(result.dryRun),
|
||||
exitCode: result.exitCode ?? null,
|
||||
});
|
||||
return { sessionId: row.agent_session_id ?? null };
|
||||
}
|
||||
|
||||
let sessionId = row.agent_session_id ?? null;
|
||||
if (!sessionId) {
|
||||
const sessionOptions = {};
|
||||
@@ -353,6 +381,7 @@ export function createAgentRunGateway({
|
||||
pendingDispatches: queuedDispatches.length,
|
||||
statusCounts,
|
||||
terminalStatuses: [...TERMINAL_STATUSES],
|
||||
toolGateway: toolGateway?.getStatus ? toolGateway.getStatus() : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user