|
@@ -1,6 +1,6 @@
|
|
|
import { paasStatus, paasText } from "@/paas"
|
|
import { paasStatus, paasText } from "@/paas"
|
|
|
|
|
|
|
|
-export type InboxKind = "approval" | "failed" | "unread"
|
|
|
|
|
|
|
+export type InboxKind = "approval" | "clarification" | "failed" | "unread"
|
|
|
export type InboxProject = { id: string; name: string }
|
|
export type InboxProject = { id: string; name: string }
|
|
|
|
|
|
|
|
export type InboxItem = {
|
|
export type InboxItem = {
|
|
@@ -53,6 +53,7 @@ export function buildInbox(input: {
|
|
|
const threads = new Map<string, Chat>()
|
|
const threads = new Map<string, Chat>()
|
|
|
for (const chat of chats) if (chat.threadID && !threads.has(chat.threadID)) threads.set(chat.threadID, chat)
|
|
for (const chat of chats) if (chat.threadID && !threads.has(chat.threadID)) threads.set(chat.threadID, chat)
|
|
|
const items = new Map<string, InboxItem>()
|
|
const items = new Map<string, InboxItem>()
|
|
|
|
|
+ const observed = new Set<string>()
|
|
|
const add = (item: InboxItem) => {
|
|
const add = (item: InboxItem) => {
|
|
|
const key = item.runID || item.id
|
|
const key = item.runID || item.id
|
|
|
if (!items.has(key)) items.set(key, item)
|
|
if (!items.has(key)) items.set(key, item)
|
|
@@ -65,6 +66,9 @@ export function buildInbox(input: {
|
|
|
const seen = seenFor(projectID)
|
|
const seen = seenFor(projectID)
|
|
|
for (const message of chat.messages) {
|
|
for (const message of chat.messages) {
|
|
|
if (message.role !== "assistant" || !message.runID) continue
|
|
if (message.role !== "assistant" || !message.runID) continue
|
|
|
|
|
+ // The loaded conversation takes precedence over the task index, including
|
|
|
|
|
+ // states that no longer need an inbox entry (running, cancelled or read).
|
|
|
|
|
+ if (message.status) observed.add(message.runID)
|
|
|
const at = message.updated || message.started || 0
|
|
const at = message.updated || message.started || 0
|
|
|
if (["waiting_human", "waiting_confirmation"].includes(message.status || ""))
|
|
if (["waiting_human", "waiting_confirmation"].includes(message.status || ""))
|
|
|
add({
|
|
add({
|
|
@@ -78,6 +82,18 @@ export function buildInbox(input: {
|
|
|
runID: message.runID,
|
|
runID: message.runID,
|
|
|
at,
|
|
at,
|
|
|
})
|
|
})
|
|
|
|
|
+ else if (message.status === "needs_clarification")
|
|
|
|
|
+ add({
|
|
|
|
|
+ id: `clarification:${message.runID}`,
|
|
|
|
|
+ kind: "clarification",
|
|
|
|
|
+ title: chat.title,
|
|
|
|
|
+ detail: "需要补充信息后才能继续",
|
|
|
|
|
+ projectID,
|
|
|
|
|
+ projectName,
|
|
|
|
|
+ chatID: chat.id,
|
|
|
|
|
+ runID: message.runID,
|
|
|
|
|
+ at,
|
|
|
|
|
+ })
|
|
|
else if (message.status === "failed")
|
|
else if (message.status === "failed")
|
|
|
add({
|
|
add({
|
|
|
id: `failed:${message.runID}`,
|
|
id: `failed:${message.runID}`,
|
|
@@ -99,7 +115,8 @@ export function buildInbox(input: {
|
|
|
id: `unread:${message.runID}`,
|
|
id: `unread:${message.runID}`,
|
|
|
kind: "unread",
|
|
kind: "unread",
|
|
|
title: chat.title,
|
|
title: chat.title,
|
|
|
- detail: chat.name,
|
|
|
|
|
|
|
+ detail:
|
|
|
|
|
+ chat.messages.find((source) => source.role === "user" && source.runID === message.runID)?.text || chat.name,
|
|
|
projectID,
|
|
projectID,
|
|
|
projectName,
|
|
projectName,
|
|
|
chatID: chat.id,
|
|
chatID: chat.id,
|
|
@@ -113,7 +130,7 @@ export function buildInbox(input: {
|
|
|
const runID = paasText(task.run_id) || paasText(task.id)
|
|
const runID = paasText(task.run_id) || paasText(task.id)
|
|
|
const threadID = paasText(task.thread_id) || paasText(task.session_id)
|
|
const threadID = paasText(task.thread_id) || paasText(task.session_id)
|
|
|
const chat = threadID ? threads.get(threadID) : undefined
|
|
const chat = threadID ? threads.get(threadID) : undefined
|
|
|
- if (!runID || !chat || items.has(runID) || !chat.projectID) continue
|
|
|
|
|
|
|
+ if (!runID || !chat || observed.has(runID) || items.has(runID) || !chat.projectID) continue
|
|
|
const projectID = chat.projectID
|
|
const projectID = chat.projectID
|
|
|
const projectName = projectNames.get(projectID)!
|
|
const projectName = projectNames.get(projectID)!
|
|
|
const seen = seenFor(projectID)
|
|
const seen = seenFor(projectID)
|
|
@@ -131,6 +148,18 @@ export function buildInbox(input: {
|
|
|
runID,
|
|
runID,
|
|
|
at,
|
|
at,
|
|
|
})
|
|
})
|
|
|
|
|
+ else if (status === "needs_clarification")
|
|
|
|
|
+ add({
|
|
|
|
|
+ id: `clarification:${runID}`,
|
|
|
|
|
+ kind: "clarification",
|
|
|
|
|
+ title: chat.title,
|
|
|
|
|
+ detail: "需要补充信息后才能继续",
|
|
|
|
|
+ projectID,
|
|
|
|
|
+ projectName,
|
|
|
|
|
+ chatID: chat.id,
|
|
|
|
|
+ runID,
|
|
|
|
|
+ at,
|
|
|
|
|
+ })
|
|
|
else if (status === "failed")
|
|
else if (status === "failed")
|
|
|
add({
|
|
add({
|
|
|
id: `failed:${runID}`,
|
|
id: `failed:${runID}`,
|
|
@@ -148,7 +177,7 @@ export function buildInbox(input: {
|
|
|
id: `unread:${runID}`,
|
|
id: `unread:${runID}`,
|
|
|
kind: "unread",
|
|
kind: "unread",
|
|
|
title: chat.title,
|
|
title: chat.title,
|
|
|
- detail: chat.name,
|
|
|
|
|
|
|
+ detail: paasText(task.input) || chat.name,
|
|
|
projectID,
|
|
projectID,
|
|
|
projectName,
|
|
projectName,
|
|
|
chatID: chat.id,
|
|
chatID: chat.id,
|
|
@@ -157,6 +186,6 @@ export function buildInbox(input: {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const priority: Record<InboxKind, number> = { approval: 0, failed: 1, unread: 2 }
|
|
|
|
|
|
|
+ const priority: Record<InboxKind, number> = { approval: 0, clarification: 1, failed: 2, unread: 3 }
|
|
|
return [...items.values()].sort((a, b) => priority[a.kind] - priority[b.kind] || b.at - a.at)
|
|
return [...items.values()].sort((a, b) => priority[a.kind] - priority[b.kind] || b.at - a.at)
|
|
|
}
|
|
}
|