fix: stabilize MindSpace local workflows

Signed-off-by: john <cynell@139.com>
This commit is contained in:
john
2026-07-12 08:12:15 +08:00
parent 32fb2cdeaf
commit a3f669d4e7
9 changed files with 107 additions and 23 deletions
+16
View File
@@ -1,4 +1,5 @@
import crypto from 'node:crypto';
import fs from 'node:fs/promises';
import path from 'node:path';
const JOB_TYPES = new Set(['generate_page', 'analyze_asset', 'summarize']);
@@ -625,6 +626,20 @@ export function createAgentJobService(pool, options = {}) {
return jobResponse({ ...job, progress_json: JSON.stringify(payload), heartbeat_at: now });
};
const setSessionId = async (jobId, token, sessionId) => {
await requireJobToken(jobId, token);
const normalizedSessionId = String(sessionId ?? '').trim();
if (!normalizedSessionId) {
throw agentJobError('Agent 会话不能为空', 'invalid_agent_job_input');
}
await pool.query(
`UPDATE h5_agent_jobs
SET session_id = ?, updated_at = ?
WHERE id = ?`,
[normalizedSessionId, nowFactory(), jobId],
);
};
const completeJob = async (jobId, token, input) => {
const job = await requireJobToken(jobId, token);
const now = nowFactory();
@@ -722,6 +737,7 @@ export function createAgentJobService(pool, options = {}) {
reapStaleJobs,
getAssetForJob,
heartbeat,
setSessionId,
completeJob,
};
}