feat(chat): add typed change-set summary message in timeline
This commit is contained in:
@@ -258,10 +258,12 @@ async function getChatMessages(auth: AuthContext | null) {
|
||||
|
||||
return items.map((m) => {
|
||||
const cs = getChangeSetFromPlanJson(m.planJson);
|
||||
const messageKind = getMessageKindFromPlanJson(m.planJson) ?? (cs ? "change_set_summary" : null);
|
||||
return {
|
||||
id: m.id,
|
||||
role: m.role === "USER" ? "user" : m.role === "ASSISTANT" ? "assistant" : "system",
|
||||
text: m.text,
|
||||
messageKind,
|
||||
requestId: null,
|
||||
eventType: null,
|
||||
phase: null,
|
||||
@@ -641,6 +643,27 @@ function getChangeSetFromPlanJson(planJson: unknown): ChangeSet | null {
|
||||
return cs as ChangeSet;
|
||||
}
|
||||
|
||||
function getMessageKindFromPlanJson(planJson: unknown): string | null {
|
||||
const debug = (planJson as any) ?? {};
|
||||
const kind = debug?.messageKind;
|
||||
if (!kind || typeof kind !== "string") return null;
|
||||
return kind;
|
||||
}
|
||||
|
||||
function renderChangeSetSummary(changeSet: ChangeSet): string {
|
||||
const totals = { created: 0, updated: 0, deleted: 0 };
|
||||
for (const item of changeSet.items) {
|
||||
if (item.action === "created") totals.created += 1;
|
||||
else if (item.action === "updated") totals.updated += 1;
|
||||
else if (item.action === "deleted") totals.deleted += 1;
|
||||
}
|
||||
|
||||
return [
|
||||
"Technical change summary",
|
||||
`Total: ${changeSet.items.length} · Created: ${totals.created} · Updated: ${totals.updated} · Archived: ${totals.deleted}`,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
async function findLatestChangeCarrierMessage(auth: AuthContext | null) {
|
||||
const ctx = requireAuth(auth);
|
||||
const items = await prisma.chatMessage.findMany({
|
||||
@@ -755,9 +778,24 @@ async function sendPilotMessage(auth: AuthContext | null, textInput: string) {
|
||||
eventType: "assistant",
|
||||
phase: "final",
|
||||
transient: false,
|
||||
changeSet,
|
||||
});
|
||||
|
||||
if (changeSet) {
|
||||
await persistChatMessage({
|
||||
teamId: ctx.teamId,
|
||||
conversationId: ctx.conversationId,
|
||||
authorUserId: null,
|
||||
role: "ASSISTANT",
|
||||
text: renderChangeSetSummary(changeSet),
|
||||
requestId,
|
||||
eventType: "note",
|
||||
phase: "final",
|
||||
transient: false,
|
||||
messageKind: "change_set_summary",
|
||||
changeSet,
|
||||
});
|
||||
}
|
||||
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -909,6 +947,7 @@ export const crmGraphqlSchema = buildSchema(`
|
||||
id: ID!
|
||||
role: String!
|
||||
text: String!
|
||||
messageKind: String
|
||||
requestId: String
|
||||
eventType: String
|
||||
phase: String
|
||||
|
||||
Reference in New Issue
Block a user