feat: split h5 direct chat from goosed tasks
This commit is contained in:
+32
-5
@@ -15,6 +15,7 @@ import {
|
||||
import { buildCurrentTimeAgentPrefix, buildTaskRoutingAgentText } from './user-memory-profile.mjs';
|
||||
import { reconcileAgentSession } from './session-reconcile.mjs';
|
||||
import { createImgproxySigner } from './imgproxy-signer.mjs';
|
||||
import { isDirectChatSessionId } from './direct-chat-service.mjs';
|
||||
|
||||
const insecureDispatcher = new Agent({
|
||||
connect: { rejectUnauthorized: false },
|
||||
@@ -55,12 +56,22 @@ function extractPublicImageStorageKey(rawUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildPublicStandardImageUrl(rawUrl, userId) {
|
||||
function resolvePublicBaseUrlFromLayout(publishLayout) {
|
||||
const publicUrl = String(publishLayout?.publicUrl ?? '').trim();
|
||||
if (!publicUrl) return resolvePublicBaseUrl();
|
||||
try {
|
||||
return new URL(publicUrl).origin;
|
||||
} catch {
|
||||
return resolvePublicBaseUrl();
|
||||
}
|
||||
}
|
||||
|
||||
function buildPublicStandardImageUrl(rawUrl, userId, publishLayout = null) {
|
||||
const storageKey = extractPublicImageStorageKey(rawUrl);
|
||||
if (!storageKey) return null;
|
||||
const match = storageKey.match(PUBLIC_IMAGE_STORAGE_KEY_PATTERN);
|
||||
if (!match || match[1] !== String(userId ?? '')) return null;
|
||||
return buildPublicUrl(resolvePublicBaseUrl(), userId, `public/images/${match[2]}`);
|
||||
return buildPublicUrl(resolvePublicBaseUrlFromLayout(publishLayout), userId, `public/images/${match[2]}`);
|
||||
}
|
||||
|
||||
async function apiFetch(target, apiSecret, pathname, init = {}) {
|
||||
@@ -491,7 +502,7 @@ function sanitizeOwnPublicHtmlUrl(publicUrl, owner, rawRelativePath, currentUser
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
url: canonicalizeStaticPageUrl(publicUrl, relativePath, canonicalRelativePath),
|
||||
url: buildPublicUrl(resolvePublicBaseUrl(), owner, canonicalRelativePath),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -698,6 +709,7 @@ export async function buildVisionPayload({
|
||||
localFetchAsset,
|
||||
llmProviderService,
|
||||
imgproxySigner = null,
|
||||
fetchImpl = undiciFetch,
|
||||
}) {
|
||||
void imgproxySigner;
|
||||
if (!llmProviderService || !userId) return null;
|
||||
@@ -730,7 +742,7 @@ export async function buildVisionPayload({
|
||||
return rawUrl;
|
||||
})();
|
||||
try {
|
||||
const response = await undiciFetch(fetchableUrl);
|
||||
const response = await fetchImpl(fetchableUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Vision fetch failed: ${response.status}`);
|
||||
}
|
||||
@@ -752,7 +764,7 @@ export async function buildVisionPayload({
|
||||
const parsed = new URL(rawUrl);
|
||||
relativePath = parsed.pathname + parsed.search;
|
||||
} catch { /* keep rawUrl */ }
|
||||
const publicStandardUrl = buildPublicStandardImageUrl(rawUrl, userId);
|
||||
const publicStandardUrl = buildPublicStandardImageUrl(rawUrl, userId, publishLayout);
|
||||
imageItems.push({
|
||||
mimeType,
|
||||
data: buffer.toString('base64'),
|
||||
@@ -1583,6 +1595,21 @@ export function createTkmindProxy({
|
||||
res.setHeader('X-TKMind-Degraded', '1');
|
||||
}
|
||||
|
||||
const directSessionIds = [...owned].filter(isDirectChatSessionId);
|
||||
if (directSessionIds.length > 0 && sessionSnapshotService?.isEnabled?.()) {
|
||||
for (const sessionId of directSessionIds) {
|
||||
if (sessionsById.has(sessionId)) continue;
|
||||
const snapshot = await sessionSnapshotService.get(sessionId).catch(() => null);
|
||||
if (!snapshot?.session) continue;
|
||||
sessionsById.set(sessionId, {
|
||||
...snapshot.session,
|
||||
message_count: snapshot.meta?.synced_msg_count ?? snapshot.messages?.length ?? 0,
|
||||
updated_at: snapshot.meta?.source_updated_at ?? snapshot.session.updated_at,
|
||||
conversation: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const sessions = [...sessionsById.values()].sort(sortSessionsByRecent);
|
||||
await enrichSessionHistory(sessions);
|
||||
if (typeof userAuth.getSessionOrigins === 'function' && sessions.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user