Patch local chat realtime and align Caddy

This commit is contained in:
kris
2026-04-10 22:12:58 +08:00
parent a084688e35
commit 1b0f126d4f
8 changed files with 144 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ import { jsonNoStore } from "@/lib/api-response";
import { requireRequestSession } from "@/lib/boss-auth";
import { subscribeBossEvents, type BossEventPayload } from "@/lib/boss-events";
import {
buildProjectMessagesRealtimePayload,
getAuditSummaryView,
getConversationHomeItemForProject,
getConversationThreadItemForProject,
@@ -24,11 +25,23 @@ function shouldEnrichConversationPatch(event: string, payload: Pick<BossEventPay
return event === "conversation.updated" || event === "project.messages.updated";
}
function shouldEnrichProjectMessagesPatch(event: string, payload: Pick<BossEventPayload, "projectId">) {
return event === "project.messages.updated" && Boolean(payload.projectId?.trim());
}
async function buildEventPayload(event: string, payload: BossEventPayload) {
if (!shouldEnrichConversationPatch(event, payload)) {
if (!shouldEnrichConversationPatch(event, payload) && !shouldEnrichProjectMessagesPatch(event, payload)) {
return payload;
}
const state = await readState();
if (shouldEnrichProjectMessagesPatch(event, payload)) {
return {
...payload,
conversationItem: getConversationHomeItemForProject(state, String(payload.projectId ?? "")),
threadConversationItem: getConversationThreadItemForProject(state, String(payload.projectId ?? "")),
projectMessagesPayload: buildProjectMessagesRealtimePayload(state, String(payload.projectId ?? "")),
};
}
return {
...payload,
conversationItem: getConversationHomeItemForProject(state, String(payload.projectId ?? "")),

View File

@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import { requireRequestSession } from "@/lib/boss-auth";
import { appendProjectMessage, buildCollaborationGate, readState } from "@/lib/boss-data";
import { jsonNoStore } from "@/lib/api-response";
import { buildProjectMessagesRealtimePayload } from "@/lib/boss-projections";
import {
getThreadConversationExecutionConflict,
queueGroupDispatchPlan,
@@ -36,21 +37,6 @@ function threadConversationFailureMessage(error?: string) {
}
}
function buildProjectMessagesPayload(
state: Awaited<ReturnType<typeof readState>>,
projectId: string,
) {
const project = state.projects.find((item) => item.id === projectId);
if (!project) {
return null;
}
return {
ok: true,
project,
devices: state.devices.filter((device) => project.deviceIds.includes(device.id)),
};
}
export async function GET(
request: NextRequest,
context: { params: Promise<{ projectId: string }> },
@@ -62,7 +48,7 @@ export async function GET(
const { projectId } = await context.params;
const state = await readState();
const payload = buildProjectMessagesPayload(state, projectId);
const payload = buildProjectMessagesRealtimePayload(state, projectId);
if (!payload) {
return jsonNoStore({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
}