fix(archied): post dashboard chat task outcomes into the conversation through the gateway
This commit is contained in:
1 parent
fe9bdefc62
commit
aabe8f7a80
11 files changed
+229
-149
No files matched your search
@@ -10,6 +10,7 @@ import {
|
||||
MessageScrollerProvider,
|
||||
MessageScrollerViewport,
|
||||
} from "@/components/ui/message-scroller";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import ChatAskCard from "./ChatAskCard.vue";
|
||||
import ChatBubble from "./ChatBubble.vue";
|
||||
import ChatChooseCard from "./ChatChooseCard.vue";
|
||||
@@ -22,6 +23,7 @@ import {
|
||||
sendMessage,
|
||||
streamingTurn,
|
||||
type ChatMessage,
|
||||
reloadTranscript,
|
||||
} from "./state";
|
||||
|
||||
/**
|
||||
@@ -72,6 +74,9 @@ const rows = computed(() => {
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
// A task this conversation started reports its outcome into it.
|
||||
useLiveResource("chat", () => void reloadTranscript());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
+39
-18
@@ -261,24 +261,7 @@ export async function selectSession(id: string): Promise<void> {
|
||||
// Resuming is the server's own command, so the transcript read below is of
|
||||
// a conversation the server considers current rather than a stale one.
|
||||
await api.chatMessage(channelID(), `/resume ${id}`);
|
||||
const [msgs, turns] = await Promise.all([
|
||||
api.chatMessages<ChatMessage[]>(id),
|
||||
api.chatTurns<ChatTurnView[]>(id),
|
||||
]);
|
||||
const byAssistantMessage = new Map<string, ChatTurnView>();
|
||||
for (const turn of turns || []) {
|
||||
const assistantID = turn.assistant_message_id || turn.AssistantMessageID;
|
||||
if (assistantID) byAssistantMessage.set(assistantID, turn);
|
||||
}
|
||||
// Tool calls belong to the turn, not the message, so a reopened
|
||||
// conversation gets its transcript back with the evidence in place.
|
||||
messages.value = (msgs || []).map((message) => {
|
||||
const messageID = message.message_id || message.MessageID;
|
||||
const turn = messageID ? byAssistantMessage.get(messageID) : undefined;
|
||||
return turn
|
||||
? { ...message, tool_calls: turn.tool_calls || turn.ToolCalls || [] }
|
||||
: message;
|
||||
});
|
||||
messages.value = await readTranscript(id);
|
||||
} catch (err) {
|
||||
statusText.value =
|
||||
(err as Error).message || "Could not load session messages";
|
||||
@@ -287,6 +270,44 @@ export async function selectSession(id: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// readTranscript reads a conversation's messages with each reply's tool calls.
|
||||
// Tool calls belong to the turn, not the message, so a reopened conversation
|
||||
// gets its transcript back with the evidence in place.
|
||||
async function readTranscript(id: string): Promise<ChatMessage[]> {
|
||||
const [msgs, turns] = await Promise.all([
|
||||
api.chatMessages<ChatMessage[]>(id),
|
||||
api.chatTurns<ChatTurnView[]>(id),
|
||||
]);
|
||||
const byAssistantMessage = new Map<string, ChatTurnView>();
|
||||
for (const turn of turns || []) {
|
||||
const assistantID = turn.assistant_message_id || turn.AssistantMessageID;
|
||||
if (assistantID) byAssistantMessage.set(assistantID, turn);
|
||||
}
|
||||
return (msgs || []).map((message) => {
|
||||
const messageID = message.message_id || message.MessageID;
|
||||
const turn = messageID ? byAssistantMessage.get(messageID) : undefined;
|
||||
return turn
|
||||
? { ...message, tool_calls: turn.tool_calls || turn.ToolCalls || [] }
|
||||
: message;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-reads the open conversation, so a message the server added (a finished
|
||||
* task's outcome) appears. A turn in flight owns the transcript, so a reload
|
||||
* waits for the next one.
|
||||
*/
|
||||
export async function reloadTranscript(): Promise<void> {
|
||||
const id = currentSession.value;
|
||||
if (!id || streamingTurn.value) return;
|
||||
try {
|
||||
const transcript = await readTranscript(id);
|
||||
if (isCurrentSession(id) && !streamingTurn.value) messages.value = transcript;
|
||||
} catch {
|
||||
// The next outcome or reopening the conversation reads it again.
|
||||
}
|
||||
}
|
||||
|
||||
// A later selection owns the loading flag: a slow read for an earlier one must
|
||||
// not clear it.
|
||||
function isCurrentSession(id: string): boolean {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export type LiveResource =
|
||||
"tasks" | "captures" | "curators" | "skills" | "updates";
|
||||
"tasks" | "captures" | "curators" | "skills" | "updates" | "chat";
|
||||
|
||||
export interface LiveEvent {
|
||||
id?: number;
|
||||
@@ -49,5 +49,6 @@ export function resourcesForEvent(raw: unknown): LiveResource[] {
|
||||
if (kind.startsWith("curator_")) resources.add("curators");
|
||||
if (kind === "curator_action") resources.add("skills");
|
||||
if (kind === "update_report") resources.add("updates");
|
||||
if (kind === "chat_outcome") resources.add("chat");
|
||||
return [...resources];
|
||||
}
|
||||
@@ -44,6 +44,7 @@ export const useSessionStore = defineStore("session", () => {
|
||||
curators: 0,
|
||||
skills: 0,
|
||||
updates: 0,
|
||||
chat: 0,
|
||||
});
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
let cursor = "";
|
||||
|
||||
Reference in new issue
Block a user