feat: split h5 direct chat from goosed tasks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { isDirectChatSessionId } from './direct-chat-service.mjs';
|
||||
|
||||
const DEFAULT_RUN_RETRY_DELAYS_MS = [1500, 5000, 15000];
|
||||
const TERMINAL_STATUSES = new Set(['succeeded', 'failed']);
|
||||
@@ -209,6 +210,7 @@ export function createAgentRunGateway({
|
||||
userAuth,
|
||||
tkmindProxy,
|
||||
toolGateway = null,
|
||||
directChatService = null,
|
||||
retryDelaysMs = DEFAULT_RUN_RETRY_DELAYS_MS,
|
||||
autoDispatch = envFlag(process.env.MEMIND_AGENT_RUN_AUTODISPATCH, true),
|
||||
maxConcurrentRuns = positiveInteger(
|
||||
@@ -384,6 +386,35 @@ export function createAgentRunGateway({
|
||||
const userMessage = safeJsonParse(row.user_message_json, {});
|
||||
const runOptions = getRunOptionsFromMessage(userMessage);
|
||||
const toolGatewayStatus = toolGateway?.getStatus ? toolGateway.getStatus() : null;
|
||||
if (directChatService?.canHandle?.({
|
||||
sessionId: row.agent_session_id ?? null,
|
||||
toolMode: runOptions.toolMode,
|
||||
userMessage,
|
||||
})) {
|
||||
try {
|
||||
const result = await directChatService.run({
|
||||
userId: row.user_id,
|
||||
sessionId: row.agent_session_id ?? null,
|
||||
requestId: row.request_id,
|
||||
userMessage,
|
||||
});
|
||||
await appendEvent(runId, 'direct_chat_completed', {
|
||||
sessionId: result.sessionId,
|
||||
providerId: result.providerId ?? null,
|
||||
model: result.model ?? null,
|
||||
billed: Boolean(result.billing?.ok),
|
||||
});
|
||||
return { sessionId: result.sessionId };
|
||||
} catch (err) {
|
||||
await appendEvent(runId, 'direct_chat_failed', {
|
||||
code: err?.code ?? null,
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
if (isDirectChatSessionId(row.agent_session_id)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (runOptions.toolMode === 'code' && toolGatewayStatus?.enabled) {
|
||||
const workingDir = userAuth?.resolveWorkingDir
|
||||
? await userAuth.resolveWorkingDir(row.user_id)
|
||||
@@ -592,6 +623,7 @@ export function createAgentRunGateway({
|
||||
} : null,
|
||||
terminalStatuses: [...TERMINAL_STATUSES],
|
||||
toolGateway: toolGateway?.getStatus ? toolGateway.getStatus() : null,
|
||||
directChat: directChatService?.getStatus ? directChatService.getStatus() : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user