502 lines
22 KiB
JavaScript
502 lines
22 KiB
JavaScript
// 业务事务内同步落盘 project.leadReports,事务提交后交由联络助手接收。
|
||
import { randomUUID } from 'node:crypto'
|
||
import { isObject, cleanText } from '../shared/utils.js'
|
||
|
||
export class LeadReporterError extends Error {
|
||
constructor(code, message) {
|
||
super(message)
|
||
this.name = 'LeadReporterError'
|
||
this.code = code
|
||
}
|
||
}
|
||
|
||
export const LEAD_REPORT_SUMMARY_LIMIT = 800
|
||
export const LEAD_REPORT_SOURCE_KINDS = Object.freeze(['sansheng-report', 'sansheng-task'])
|
||
export const LEAD_REPORT_STATUSES = Object.freeze(['pending', 'delivered', 'failed'])
|
||
|
||
const SOURCE_KIND_SET = new Set(LEAD_REPORT_SOURCE_KINDS)
|
||
const BRIEF_EVENTS = new Set([
|
||
'approval_request', 'user_decision', 'decision_required',
|
||
'blocked', 'blockage', 'workflow_blocked', 'workflow_blockage',
|
||
'delivery', 'delivered', 'workflow_delivery', 'workflow_deliver', 'workflow_delivered',
|
||
'menxia_accept',
|
||
'fast_lane_done', 'fast_lane_failed', 'fast_lane_escalated',
|
||
])
|
||
|
||
function briefEligible(report) {
|
||
return report.needsUserDecision === true || BRIEF_EVENTS.has(report.event)
|
||
}
|
||
|
||
function approvalIdOf(report) {
|
||
if (report?.event !== 'approval_request') return ''
|
||
const transitionId = cleanText(report.transitionId)
|
||
const legacyId = transitionId.startsWith('approval:') ? cleanText(transitionId.slice('approval:'.length)) : ''
|
||
return cleanText(report.approvalId) || legacyId
|
||
}
|
||
|
||
function truncateSummary(value) {
|
||
const chars = Array.from(String(value ?? ''))
|
||
return chars.length <= LEAD_REPORT_SUMMARY_LIMIT ? chars.join('') : chars.slice(0, LEAD_REPORT_SUMMARY_LIMIT).join('')
|
||
}
|
||
|
||
function snapshotText(value) {
|
||
if (typeof value === 'string') return value
|
||
if (value === null || value === undefined) return ''
|
||
if (typeof value === 'object') {
|
||
try { return JSON.stringify(value) } catch { return String(value) }
|
||
}
|
||
return String(value)
|
||
}
|
||
|
||
function projectOf(state, projectId) {
|
||
const project = state?.projects?.[projectId]
|
||
if (!project) throw new LeadReporterError('sansheng/not-found', `项目 ${projectId} 不存在`)
|
||
return project
|
||
}
|
||
|
||
function reportsOf(project) {
|
||
if (!Array.isArray(project.leadReports)) project.leadReports = []
|
||
return project.leadReports
|
||
}
|
||
|
||
function findReport(project, reportId) {
|
||
return (project.leadReports ?? []).find(item => item.reportId === reportId || item.id === reportId)
|
||
}
|
||
|
||
function findTask(project, taskId) {
|
||
return taskId ? ((project.tasks ?? []).find(item => item.id === taskId) ?? null) : null
|
||
}
|
||
|
||
// 消息字段在 record 时冻结;这里只拼报告快照,不读取后续状态。
|
||
export function buildLeadReportMessage(report) {
|
||
const requirement = report?.requirementId
|
||
? `${report.requirementId}${report.requirementRevision === null || report.requirementRevision === undefined ? '' : ` v${report.requirementRevision}`}`
|
||
: '无'
|
||
return [
|
||
'【丞相回报】',
|
||
`回报编号:${report?.reportId ?? ''}`,
|
||
...(approvalIdOf(report) ? [`审批编号:${approvalIdOf(report)}`] : []),
|
||
`任务:${report?.taskId ?? '无'}`,
|
||
`需求:${requirement}`,
|
||
`事件:${report?.event ?? ''}`,
|
||
`阶段:${report?.stage ?? '无'}`,
|
||
`执行席位:${report?.ownerSeatId ?? '无'}`,
|
||
`结果摘要:${truncateSummary(report?.summary ?? report?.textSnapshot ?? '')}`,
|
||
`下一步:${report?.nextStep || '无'}`,
|
||
`需要用户决策:${report?.needsUserDecision ? '是' : '否'}`,
|
||
].join('\n')
|
||
}
|
||
|
||
function defaultCreateUserMessage(input) {
|
||
return { role: 'user', content: input.content, source: input.source }
|
||
}
|
||
|
||
function taskStateProblem(project, report) {
|
||
if (!report.taskId) return ''
|
||
const task = findTask(project, report.taskId)
|
||
if (!task) return 'task-not-found'
|
||
if (['cancelled', 'reconfirm'].includes(task.status) || (task.kind === 'workflow' && task.status === 'done')) {
|
||
return 'task-terminated'
|
||
}
|
||
const req = task.requirementId ? (project.requirements ?? []).find(item => item.id === task.requirementId) : null
|
||
if (req && report.requirementRevision !== null && report.requirementRevision !== undefined
|
||
&& String(req.revision) !== String(report.requirementRevision)) {
|
||
return 'task-requirement-changed'
|
||
}
|
||
if (report.decisionId && !task.decisions?.some(item => item.id === report.decisionId && item.status === 'pending')) return 'decision-closed'
|
||
if (report.consultationId && !task.consultations?.some(item => item.id === report.consultationId)) return 'consultation-unavailable'
|
||
if (!report.decisionId && !report.consultationId && report.transitionId && task.lastTransitionId && task.lastTransitionId !== report.transitionId) {
|
||
return 'task-transition-changed'
|
||
}
|
||
if (report.requirementRevision !== null && report.requirementRevision !== undefined
|
||
&& task.requirementRevision !== null && task.requirementRevision !== undefined
|
||
&& String(task.requirementRevision) !== String(report.requirementRevision)) {
|
||
return 'task-requirement-changed'
|
||
}
|
||
if (!task.lastTransitionId && report.stage && task.stage && String(task.stage) !== String(report.stage)) {
|
||
return 'task-stage-changed'
|
||
}
|
||
return ''
|
||
}
|
||
|
||
function recordIntoProject(project, projectId, event, at) {
|
||
const taskRef = isObject(event.task) ? event.task : null
|
||
const taskId = cleanText(event.taskId) || cleanText(taskRef?.id) || null
|
||
const task = taskRef ?? findTask(project, taskId)
|
||
const transitionId = cleanText(event.transitionId)
|
||
|| cleanText(event.lastTransitionId)
|
||
|| cleanText(task?.lastTransitionId)
|
||
|| cleanText(event.reportId)
|
||
if (!transitionId) throw new LeadReporterError('sansheng/lead-report-invalid', '回报事件缺少 transitionId')
|
||
const requestedReportId = cleanText(event.reportId)
|
||
const reports = reportsOf(project)
|
||
const existing = reports.find(item => item.transitionId === transitionId
|
||
|| (requestedReportId && item.reportId === requestedReportId))
|
||
if (existing) {
|
||
const snapshot = structuredClone(existing)
|
||
return { ...structuredClone(snapshot), report: snapshot, created: false, duplicate: true }
|
||
}
|
||
const reportId = requestedReportId || randomUUID()
|
||
const textSnapshot = snapshotText(event.textSnapshot ?? '')
|
||
const report = {
|
||
id: reportId,
|
||
reportId,
|
||
projectId,
|
||
transitionId,
|
||
taskId,
|
||
requirementId: event.requirementId ?? task?.requirementId ?? null,
|
||
requirementRevision: event.requirementRevision ?? task?.requirementRevision ?? null,
|
||
event: cleanText(event.event),
|
||
...(event.decisionId ? { decisionId: event.decisionId } : {}),
|
||
...(event.consultationId ? { consultationId: event.consultationId } : {}),
|
||
stage: event.stage ?? task?.stage ?? null,
|
||
ownerSeatId: event.ownerSeatId ?? task?.ownerSeatId ?? null,
|
||
textSnapshot,
|
||
sourceKind: SOURCE_KIND_SET.has(event.sourceKind) ? event.sourceKind : 'sansheng-report',
|
||
status: 'pending',
|
||
summary: truncateSummary(cleanText(event.summary) || textSnapshot),
|
||
nextStep: cleanText(event.nextStep),
|
||
needsUserDecision: Boolean(event.needsUserDecision),
|
||
error: null,
|
||
createdAt: at,
|
||
updatedAt: at,
|
||
}
|
||
const approvalId = approvalIdOf(event)
|
||
if (approvalId) report.approvalId = approvalId
|
||
reports.push(report)
|
||
const snapshot = structuredClone(report)
|
||
return { ...structuredClone(snapshot), report: snapshot, created: true, duplicate: false }
|
||
}
|
||
|
||
// 供 service 在既有业务事务内同步调用:只写 project.leadReports,不做任何异步/宿主调用。
|
||
export function recordLeadReportInState(state, projectId, event, now = Date.now()) {
|
||
if (!isObject(event)) throw new LeadReporterError('sansheng/lead-report-invalid', '回报事件必须是对象')
|
||
const at = typeof now === 'function' ? now() : Number(now)
|
||
return recordIntoProject(projectOf(state, projectId), projectId, event, at)
|
||
}
|
||
|
||
export function createLeadReporter({ store, host = {}, ensureLeadAssistant, now = () => Date.now() } = {}) {
|
||
if (!store || typeof store.get !== 'function' || typeof store.mutate !== 'function') {
|
||
throw new LeadReporterError('sansheng/lead-report-store', 'createLeadReporter 需要 store.ensureLoaded/get/mutate')
|
||
}
|
||
const clock = typeof now === 'function' ? now : () => Number(now)
|
||
const inFlight = new Set()
|
||
const flushQueues = new Map()
|
||
const ensureLoaded = async () => { if (typeof store.ensureLoaded === 'function') await store.ensureLoaded() }
|
||
|
||
async function record(projectId, event = {}) {
|
||
await ensureLoaded()
|
||
if (!isObject(event)) throw new LeadReporterError('sansheng/lead-report-invalid', '回报事件必须是对象')
|
||
let outcome = null
|
||
await store.mutate(state => {
|
||
outcome = recordIntoProject(projectOf(state, projectId), projectId, event, clock())
|
||
})
|
||
return outcome
|
||
}
|
||
|
||
async function list(projectId) {
|
||
await ensureLoaded()
|
||
const project = store.get(projectId)
|
||
if (!project) throw new LeadReporterError('sansheng/not-found', `项目 ${projectId} 不存在`)
|
||
return (project.leadReports ?? []).map(item => structuredClone(item))
|
||
}
|
||
|
||
async function resolveLeadAgent(sessionId) {
|
||
let agent = host.agents?.get?.(sessionId)
|
||
if (!agent && typeof host.sessionController?.resolveAgent === 'function') {
|
||
try {
|
||
const resolved = await host.sessionController.resolveAgent(sessionId)
|
||
if (resolved && !('error' in resolved)) agent = resolved.agent
|
||
} catch { /* 宿主未提供可解析会话时按不可用处理 */ }
|
||
}
|
||
return agent
|
||
}
|
||
|
||
async function markFailed(projectId, reportId, reason) {
|
||
const saved = await store.mutate(state => {
|
||
const current = findReport(projectOf(state, projectId), reportId)
|
||
if (!current || current.status !== 'pending' || current.deliveryAttemptId) return current ? structuredClone(current) : null
|
||
current.status = 'failed'
|
||
current.error = reason
|
||
current.updatedAt = clock()
|
||
return structuredClone(current)
|
||
})
|
||
if (saved?.status === 'delivered' || saved?.deliveryAttemptId) return reportResult(saved)
|
||
return { ok: false, status: saved?.status ?? 'failed', reason, error: reason, report: saved }
|
||
}
|
||
|
||
function boundSession(project, role) {
|
||
const binding = role === 'liaison' ? project?.leadAssistants?.liaison : project?.seats?.lead
|
||
return binding?.status === 'bound' ? binding.sessionId : null
|
||
}
|
||
|
||
async function resolveTarget(role, sessionId) {
|
||
if (!sessionId) return null
|
||
const agent = await resolveLeadAgent(sessionId)
|
||
if (typeof agent?.followup !== 'function' || (agent.session?.id && agent.session.id !== sessionId)) return null
|
||
if (role === 'liaison' && host.isLeadAssistantReady?.(agent, role) === false) return null
|
||
return { role, sessionId, agent, registered: Boolean(host.agents?.get?.(sessionId)) }
|
||
}
|
||
|
||
function targetIsCurrent(project, target) {
|
||
const currentAgent = host.agents?.get?.(target.sessionId)
|
||
return boundSession(project, target.role) === target.sessionId
|
||
&& (!(target.registered || currentAgent) || currentAgent === target.agent)
|
||
&& typeof target.agent.followup === 'function'
|
||
}
|
||
|
||
function reportResult(report) {
|
||
if (!report) return { ok: false, status: 'not-found', reason: 'not-found' }
|
||
if (report.status === 'delivered') return { ok: true, status: 'delivered', duplicate: true, report: structuredClone(report) }
|
||
if (report.status !== 'pending') return { ok: false, status: report.status, reason: 'not-pending', report: structuredClone(report) }
|
||
if (report.deliveryAttemptId) return { ok: false, status: 'unknown', reason: 'delivery-outcome-unknown', report: structuredClone(report) }
|
||
return null
|
||
}
|
||
|
||
function createMessage(text, source) {
|
||
const factory = typeof host.createUserMessage === 'function' ? host.createUserMessage : defaultCreateUserMessage
|
||
return factory({ content: [{ type: 'text', text }], source })
|
||
}
|
||
|
||
async function sendToTarget(projectId, id, target) {
|
||
const project = store.get(projectId)
|
||
const report = project ? findReport(project, id) : null
|
||
const settled = reportResult(report)
|
||
if (settled) return settled
|
||
const problem = taskStateProblem(project, report)
|
||
if (problem) return markFailed(projectId, id, problem)
|
||
if (!target || !targetIsCurrent(project, target)) return null
|
||
|
||
let message
|
||
try {
|
||
message = await createMessage(buildLeadReportMessage(report), {
|
||
kind: report.sourceKind, reportId: report.reportId, taskId: report.taskId,
|
||
})
|
||
} catch (error) {
|
||
return markFailed(projectId, id, String(error?.message ?? error))
|
||
}
|
||
|
||
const attemptId = randomUUID()
|
||
const claimed = await store.mutate(state => {
|
||
const latest = projectOf(state, projectId)
|
||
const current = findReport(latest, id)
|
||
if (current?.status !== 'pending' || current.deliveryAttemptId || taskStateProblem(latest, current)
|
||
|| !targetIsCurrent(latest, target)) return false
|
||
current.deliveryAttemptId = attemptId
|
||
return true
|
||
})
|
||
const latest = store.get(projectId)
|
||
const current = latest ? findReport(latest, id) : null
|
||
if (!claimed || current?.deliveryAttemptId !== attemptId) {
|
||
const result = reportResult(current)
|
||
if (result) return result
|
||
const latestProblem = taskStateProblem(latest, current)
|
||
return latestProblem ? markFailed(projectId, id, latestProblem) : null
|
||
}
|
||
|
||
const latestProblem = taskStateProblem(latest, current)
|
||
if (current.status !== 'pending' || latestProblem || !targetIsCurrent(latest, target)) {
|
||
await store.mutate(state => {
|
||
const saved = findReport(projectOf(state, projectId), id)
|
||
if (saved?.deliveryAttemptId === attemptId) delete saved.deliveryAttemptId
|
||
})
|
||
const refreshed = store.get(projectId)
|
||
const refreshedReport = refreshed ? findReport(refreshed, id) : null
|
||
const result = reportResult(refreshedReport)
|
||
if (result) return result
|
||
const refreshedProblem = taskStateProblem(refreshed, refreshedReport)
|
||
return refreshedProblem ? markFailed(projectId, id, refreshedProblem) : null
|
||
}
|
||
|
||
let sendError = null
|
||
try {
|
||
await target.agent.followup(message)
|
||
} catch (error) {
|
||
sendError = String(error?.message ?? error)
|
||
}
|
||
const finalized = await store.mutate(state => {
|
||
const saved = findReport(projectOf(state, projectId), id)
|
||
if (saved?.deliveryAttemptId !== attemptId || saved.status !== 'pending') return saved ? structuredClone(saved) : null
|
||
delete saved.deliveryAttemptId
|
||
const at = clock()
|
||
saved.updatedAt = at
|
||
saved.status = sendError === null ? 'delivered' : 'failed'
|
||
if (sendError === null) saved.deliveredAt = at
|
||
saved.error = sendError
|
||
return structuredClone(saved)
|
||
})
|
||
return {
|
||
ok: sendError === null && finalized?.status === 'delivered',
|
||
status: finalized?.status ?? (sendError === null ? 'delivered' : 'failed'),
|
||
report: finalized,
|
||
error: sendError ?? undefined,
|
||
}
|
||
}
|
||
|
||
async function send(projectId, reportId) {
|
||
await ensureLoaded()
|
||
const id = cleanText(reportId)
|
||
if (!id) throw new LeadReporterError('sansheng/lead-report-invalid', '缺少 reportId')
|
||
const project = store.get(projectId)
|
||
if (!project) throw new LeadReporterError('sansheng/not-found', `项目 ${projectId} 不存在`)
|
||
const report = findReport(project, id)
|
||
const flightKey = JSON.stringify([projectId, report?.reportId ?? id])
|
||
if (inFlight.has(flightKey)) return { ok: false, status: 'in-flight', reason: 'in-flight' }
|
||
const settled = reportResult(report)
|
||
if (settled) return settled
|
||
const problem = taskStateProblem(project, report)
|
||
inFlight.add(flightKey)
|
||
try {
|
||
if (problem) return await markFailed(projectId, id, problem)
|
||
if (typeof ensureLeadAssistant === 'function') {
|
||
let liaison
|
||
try {
|
||
liaison = await ensureLeadAssistant(projectId, 'liaison')
|
||
} catch (error) {
|
||
console.warn('[sansheng] 联络助手不可用,回报转投丞相:', error?.message ?? error)
|
||
}
|
||
const target = liaison?.status === 'bound' ? await resolveTarget('liaison', liaison.sessionId) : null
|
||
const result = await sendToTarget(projectId, id, target)
|
||
if (result) return result
|
||
}
|
||
|
||
const sessionId = boundSession(store.get(projectId), 'lead')
|
||
if (!sessionId) return await markFailed(projectId, id, 'lead-seat-unbound')
|
||
const result = await sendToTarget(projectId, id, await resolveTarget('lead', sessionId))
|
||
if (result) return result
|
||
const stillBound = boundSession(store.get(projectId), 'lead') === sessionId
|
||
return await markFailed(projectId, id, stillBound ? `丞相会话不可用:${sessionId}` : 'lead-seat-unbound')
|
||
} finally {
|
||
inFlight.delete(flightKey)
|
||
}
|
||
}
|
||
|
||
function isBoundLiaison(project, actor) {
|
||
const role = actor?.assistantRole ?? actor?.seatId
|
||
const sessionId = actor?.sessionId
|
||
return role === 'liaison' && Boolean(sessionId) && boundSession(project, 'liaison') === sessionId
|
||
&& (actor.projectId == null || actor.projectId === project.id)
|
||
&& (!actor.agent || host.agents?.get?.(sessionId) === actor.agent)
|
||
}
|
||
|
||
function briefReport(project, reportId, actor) {
|
||
if (!isBoundLiaison(project, actor)) {
|
||
throw new LeadReporterError('sansheng/forbidden', '只有本项目已绑定的联络助手可以提交简报')
|
||
}
|
||
const report = (project.leadReports ?? []).find(item => item.reportId === reportId)
|
||
if (!report) throw new LeadReporterError('sansheng/not-found', '回报不存在')
|
||
if (!briefEligible(report)) throw new LeadReporterError('sansheng/lead-brief-ineligible', '此回报无需转交丞相')
|
||
return report
|
||
}
|
||
|
||
function previousBrief(report) {
|
||
if (!report.brief) return null
|
||
const delivered = report.brief.status === 'delivered'
|
||
return { ok: delivered, status: delivered ? 'delivered' : 'unknown', reportId: report.reportId, duplicate: true }
|
||
}
|
||
|
||
async function brief(projectId, input = {}, actor = {}) {
|
||
await ensureLoaded()
|
||
const reportId = cleanText(input?.reportId)
|
||
const summary = truncateSummary(cleanText(input?.summary))
|
||
if (!reportId || !summary) throw new LeadReporterError('sansheng/lead-report-invalid', '简报需要回报编号与摘要')
|
||
const project = store.get(projectId)
|
||
const report = briefReport(project, reportId, actor)
|
||
const existing = previousBrief(report)
|
||
if (existing) return existing
|
||
const target = await resolveTarget('lead', boundSession(project, 'lead'))
|
||
if (!target) return { ok: false, status: 'not-sent', reportId, reason: 'lead-session-unavailable' }
|
||
|
||
const approvalId = approvalIdOf(report)
|
||
const text = [
|
||
'【丞相简报】',
|
||
'回报编号:' + reportId,
|
||
'事件:' + report.event,
|
||
...(report.taskId ? ['任务:' + report.taskId] : []),
|
||
...(report.decisionId ? ['裁决编号:' + report.decisionId] : []),
|
||
...(approvalId ? ['审批编号:' + approvalId] : []),
|
||
'简报摘要:' + summary,
|
||
].join('\n')
|
||
let message
|
||
try {
|
||
message = await createMessage(text, { kind: 'sansheng-summary', reportId, taskId: report.taskId })
|
||
} catch (error) {
|
||
return { ok: false, status: 'not-sent', reportId, reason: 'message-factory-failed', error: String(error?.message ?? error) }
|
||
}
|
||
|
||
const attemptId = randomUUID()
|
||
const claimFailure = await store.mutate(state => {
|
||
const latest = projectOf(state, projectId)
|
||
const current = briefReport(latest, reportId, actor)
|
||
const duplicate = previousBrief(current)
|
||
if (duplicate) return duplicate
|
||
if (!targetIsCurrent(latest, target)) return { ok: false, status: 'not-sent', reportId, reason: 'lead-session-unavailable' }
|
||
current.brief = { attemptId, status: 'sending', summary, createdAt: clock() }
|
||
return null
|
||
})
|
||
if (claimFailure) return claimFailure
|
||
|
||
const latest = store.get(projectId)
|
||
const current = latest && findReport(latest, reportId)
|
||
if (current?.brief?.attemptId !== attemptId || !isBoundLiaison(latest, actor) || !targetIsCurrent(latest, target)) {
|
||
await store.mutate(state => {
|
||
const saved = findReport(projectOf(state, projectId), reportId)
|
||
if (saved?.brief?.attemptId === attemptId) delete saved.brief
|
||
})
|
||
return { ok: false, status: 'not-sent', reportId, reason: 'binding-changed' }
|
||
}
|
||
|
||
let sendError = null
|
||
try {
|
||
await target.agent.followup(message)
|
||
} catch (error) {
|
||
sendError = String(error?.message ?? error)
|
||
}
|
||
const status = sendError === null ? 'delivered' : 'unknown'
|
||
await store.mutate(state => {
|
||
const saved = findReport(projectOf(state, projectId), reportId)
|
||
if (saved?.brief?.attemptId === attemptId) {
|
||
saved.brief.status = status
|
||
saved.brief.updatedAt = clock()
|
||
}
|
||
})
|
||
return { ok: sendError === null, status, reportId, ...(sendError === null ? {} : { error: sendError }) }
|
||
}
|
||
|
||
async function runFlush(projectId) {
|
||
await ensureLoaded()
|
||
const project = store.get(projectId)
|
||
if (!project) throw new LeadReporterError('sansheng/not-found', `项目 ${projectId} 不存在`)
|
||
const pending = (project.leadReports ?? [])
|
||
.filter(item => item.status === 'pending')
|
||
.sort((a, b) => (a.createdAt ?? 0) - (b.createdAt ?? 0))
|
||
.map(item => item.reportId)
|
||
const sent = []
|
||
for (const reportId of pending) {
|
||
const result = await send(projectId, reportId)
|
||
sent.push({ reportId, ...result })
|
||
}
|
||
return sent
|
||
}
|
||
|
||
function flush(projectId) {
|
||
const prev = flushQueues.get(projectId) ?? Promise.resolve()
|
||
const next = prev.then(() => runFlush(projectId), () => runFlush(projectId))
|
||
const guarded = next.finally(() => { if (flushQueues.get(projectId) === guarded) flushQueues.delete(projectId) })
|
||
flushQueues.set(projectId, guarded)
|
||
return guarded
|
||
}
|
||
|
||
async function recoverAll() {
|
||
await ensureLoaded()
|
||
const out = {}
|
||
for (const project of store.list()) {
|
||
try { out[project.id] = await flush(project.id) }
|
||
catch (error) { out[project.id] = { error: error?.message ?? String(error) } }
|
||
}
|
||
return out
|
||
}
|
||
|
||
return { record, list, send, brief, flush, recoverAll, liaisonEnabled: typeof ensureLeadAssistant === 'function' }
|
||
}
|