feat: split h5 direct chat from goosed tasks
This commit is contained in:
+25
-3
@@ -164,6 +164,7 @@ import { createScheduleService } from './schedule-service.mjs';
|
||||
import { createFeedbackService } from './user-feedback.mjs';
|
||||
import { startScheduleReminderWorker } from './schedule-reminder-worker.mjs';
|
||||
import { createLlmProviderService, RELAY_BOOTSTRAP } from './llm-providers.mjs';
|
||||
import { createDirectChatService, isDirectChatSessionId, sendDirectChatSessionEvents } from './direct-chat-service.mjs';
|
||||
import { createSessionSnapshotService } from './session-snapshot.mjs';
|
||||
import { createConversationMemoryService } from './conversation-memory.mjs';
|
||||
import { createManagedMemoryV2Runtime } from './memory-v2-runtime.mjs';
|
||||
@@ -285,6 +286,7 @@ let userAuth = null;
|
||||
let tkmindProxy = null;
|
||||
let agentRunGateway = null;
|
||||
let toolGateway = null;
|
||||
let directChatService = null;
|
||||
let sessionSnapshotService = null;
|
||||
let conversationMemoryService = null;
|
||||
let memoryV2 = null;
|
||||
@@ -530,6 +532,13 @@ async function bootstrapUserAuth() {
|
||||
sessionSnapshotService = createSessionSnapshotService(pool, {
|
||||
conversationMemoryService,
|
||||
});
|
||||
directChatService = createDirectChatService({
|
||||
userAuth,
|
||||
llmProviderService,
|
||||
sessionSnapshotService,
|
||||
memoryV2,
|
||||
conversationMemoryService,
|
||||
});
|
||||
tkmindProxy = createTkmindProxy({
|
||||
apiTarget: API_TARGET,
|
||||
apiTargets: API_TARGETS,
|
||||
@@ -554,6 +563,7 @@ async function bootstrapUserAuth() {
|
||||
userAuth,
|
||||
tkmindProxy,
|
||||
toolGateway,
|
||||
directChatService,
|
||||
autoDispatch: ['1', 'true', 'yes', 'on'].includes(
|
||||
String(process.env.MEMIND_AGENT_RUN_AUTODISPATCH ?? '1').trim().toLowerCase(),
|
||||
),
|
||||
@@ -4450,7 +4460,7 @@ api.get('/sessions/:sessionId', async (req, res, next) => {
|
||||
const canUseSnapshotCache = hintMc != null && hintUa != null;
|
||||
const mcMatch = snapshot.meta.synced_msg_count === hintMc;
|
||||
const uaMatch = snapshot.meta.source_updated_at === hintUa;
|
||||
if (canUseSnapshotCache && mcMatch && uaMatch) {
|
||||
if (isDirectChatSessionId(sessionId) || (canUseSnapshotCache && mcMatch && uaMatch)) {
|
||||
const sanitizedMessages = sanitizeSessionConversationPublicHtmlLinks(
|
||||
snapshot.messages,
|
||||
req.currentUser,
|
||||
@@ -4507,12 +4517,17 @@ api.get('/sessions/:sessionId', async (req, res, next) => {
|
||||
api.delete('/sessions/:sessionId', async (req, res, next) => {
|
||||
await userAuthReady;
|
||||
if (!userAuth || !tkmindProxy) return next();
|
||||
const sessionId = req.params.sessionId;
|
||||
const owns = await userAuth.ownsSession(req.currentUser.id, sessionId);
|
||||
const sessionId = req.params.sessionId;
|
||||
const owns = await userAuth.ownsSession(req.currentUser.id, sessionId);
|
||||
if (!owns) {
|
||||
return res.status(403).json({ message: '无权访问该会话' });
|
||||
}
|
||||
try {
|
||||
if (isDirectChatSessionId(sessionId)) {
|
||||
await userAuth.unregisterAgentSession(req.currentUser.id, sessionId);
|
||||
void sessionSnapshotService?.remove(sessionId).catch(() => {});
|
||||
return res.status(204).end();
|
||||
}
|
||||
const deleteTarget = await tkmindProxy.resolveTarget(sessionId);
|
||||
const upstream = await tkmindProxy.apiFetchTo(deleteTarget, `/sessions/${encodeURIComponent(sessionId)}`, {
|
||||
method: 'DELETE',
|
||||
@@ -4538,6 +4553,13 @@ api.get('/sessions/:sessionId/events', async (req, res, next) => {
|
||||
if (!owns) {
|
||||
return res.status(403).json({ message: '无权访问该会话' });
|
||||
}
|
||||
if (isDirectChatSessionId(sessionId)) {
|
||||
const snapshot = await sessionSnapshotService?.get(sessionId).catch(() => null);
|
||||
if (!snapshot) {
|
||||
return res.status(404).json({ message: '会话不存在' });
|
||||
}
|
||||
return sendDirectChatSessionEvents(req, res, snapshot);
|
||||
}
|
||||
const publishDir = resolveMindSpaceUserPublishDir(__dirname, { id: req.currentUser.id });
|
||||
const syncPublicHtmlDuringStream = (event) => {
|
||||
materializePublicHtmlWritesFromSessionEvent(event, { publishDir });
|
||||
|
||||
Reference in New Issue
Block a user