Add dashboard room activity timeline
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { StatusSnapshot } from './status-dashboard.js';
|
||||
import type { PairedTask, ScheduledTask } from './types.js';
|
||||
import type { PairedTurnAttemptRecord, PairedTurnRecord } from './db.js';
|
||||
import type {
|
||||
NewMessage,
|
||||
PairedTask,
|
||||
PairedTurnOutput,
|
||||
ScheduledTask,
|
||||
} from './types.js';
|
||||
import {
|
||||
buildWebDashboardRoomActivity,
|
||||
buildWebDashboardOverview,
|
||||
sanitizeScheduledTask,
|
||||
} from './web-dashboard-data.js';
|
||||
@@ -230,6 +237,125 @@ describe('web dashboard data', () => {
|
||||
expect(sanitized.promptPreview).not.toContain('plain-secret-value');
|
||||
});
|
||||
|
||||
it('builds redacted room activity from messages and paired turn output', () => {
|
||||
const task = makePairedTask({
|
||||
id: 'paired-room-1',
|
||||
chat_jid: 'dc:ops',
|
||||
status: 'in_review',
|
||||
round_trip_count: 3,
|
||||
updated_at: '2026-04-26T05:30:00.000Z',
|
||||
});
|
||||
const turn: PairedTurnRecord = {
|
||||
turn_id: 'turn-1',
|
||||
task_id: task.id,
|
||||
task_updated_at: task.updated_at,
|
||||
role: 'reviewer',
|
||||
intent_kind: 'reviewer-turn',
|
||||
state: 'queued',
|
||||
executor_service_id: null,
|
||||
executor_agent_type: null,
|
||||
attempt_no: 0,
|
||||
created_at: '2026-04-26T05:19:00.000Z',
|
||||
updated_at: '2026-04-26T05:31:00.000Z',
|
||||
completed_at: null,
|
||||
last_error: null,
|
||||
};
|
||||
const attempt: PairedTurnAttemptRecord = {
|
||||
attempt_id: 'turn-1:attempt:2',
|
||||
parent_attempt_id: null,
|
||||
parent_handoff_id: null,
|
||||
continuation_handoff_id: null,
|
||||
turn_id: 'turn-1',
|
||||
task_id: task.id,
|
||||
task_updated_at: task.updated_at,
|
||||
role: 'reviewer',
|
||||
intent_kind: 'reviewer-turn',
|
||||
state: 'running',
|
||||
executor_service_id: 'claude-reviewer',
|
||||
executor_agent_type: 'claude-code',
|
||||
active_run_id: 'run-reviewer-1',
|
||||
attempt_no: 2,
|
||||
created_at: '2026-04-26T05:20:00.000Z',
|
||||
updated_at: '2026-04-26T05:31:00.000Z',
|
||||
completed_at: null,
|
||||
last_error: 'OPENAI_API_KEY=plain-secret-value',
|
||||
};
|
||||
const outputs: PairedTurnOutput[] = [
|
||||
{
|
||||
id: 1,
|
||||
task_id: task.id,
|
||||
turn_number: 1,
|
||||
role: 'owner',
|
||||
output_text: 'owner output',
|
||||
verdict: 'step_done',
|
||||
created_at: '2026-04-26T05:25:00.000Z',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
task_id: task.id,
|
||||
turn_number: 2,
|
||||
role: 'reviewer',
|
||||
output_text: 'reviewer output with BOT_TOKEN=plain-secret-value',
|
||||
verdict: null,
|
||||
created_at: '2026-04-26T05:30:00.000Z',
|
||||
},
|
||||
];
|
||||
const messages: NewMessage[] = [
|
||||
{
|
||||
id: 'msg-1',
|
||||
chat_jid: 'dc:ops',
|
||||
sender: 'user-1',
|
||||
sender_name: '눈쟁이',
|
||||
content: 'latest message',
|
||||
timestamp: '2026-04-26T05:29:00.000Z',
|
||||
is_from_me: false,
|
||||
is_bot_message: false,
|
||||
message_source_kind: 'human',
|
||||
},
|
||||
];
|
||||
|
||||
const activity = buildWebDashboardRoomActivity({
|
||||
serviceId: 'codex-main',
|
||||
entry: {
|
||||
jid: 'dc:ops',
|
||||
name: '#ops',
|
||||
folder: 'ops',
|
||||
agentType: 'codex',
|
||||
status: 'processing',
|
||||
elapsedMs: 15_000,
|
||||
pendingMessages: true,
|
||||
pendingTasks: 1,
|
||||
},
|
||||
pairedTask: task,
|
||||
turns: [turn],
|
||||
attempts: [attempt],
|
||||
outputs,
|
||||
messages,
|
||||
outputLimit: 1,
|
||||
});
|
||||
|
||||
expect(activity.pairedTask).toMatchObject({
|
||||
id: 'paired-room-1',
|
||||
roundTripCount: 3,
|
||||
currentTurn: {
|
||||
role: 'reviewer',
|
||||
state: 'running',
|
||||
attemptNo: 2,
|
||||
lastError: 'OPENAI_API_KEY=<redacted>',
|
||||
},
|
||||
outputs: [
|
||||
{
|
||||
turnNumber: 2,
|
||||
role: 'reviewer',
|
||||
outputText: 'reviewer output with BOT_TOKEN=<redacted>',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(activity.messages).toMatchObject([
|
||||
{ senderName: '눈쟁이', content: 'latest message' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds typed inbox items from pending rooms, paired tasks, and CI failures', () => {
|
||||
const snapshots: StatusSnapshot[] = [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { isWatchCiTask } from './task-watch-status.js';
|
||||
import type { PairedTurnAttemptRecord, PairedTurnRecord } from './db.js';
|
||||
import type { StatusSnapshot, UsageRowSnapshot } from './status-dashboard.js';
|
||||
import type { PairedTask, ScheduledTask } from './types.js';
|
||||
import type {
|
||||
NewMessage,
|
||||
PairedTask,
|
||||
PairedTurnOutput,
|
||||
ScheduledTask,
|
||||
} from './types.js';
|
||||
|
||||
export interface SanitizedScheduledTask {
|
||||
id: string;
|
||||
@@ -57,6 +63,63 @@ export interface WebDashboardOverview {
|
||||
inbox: InboxItem[];
|
||||
}
|
||||
|
||||
export interface WebDashboardRoomMessage {
|
||||
id: string;
|
||||
sender: string;
|
||||
senderName: string;
|
||||
content: string;
|
||||
timestamp: string;
|
||||
isFromMe: boolean;
|
||||
isBotMessage: boolean;
|
||||
sourceKind: NonNullable<NewMessage['message_source_kind']>;
|
||||
}
|
||||
|
||||
export interface WebDashboardRoomTurn {
|
||||
turnId: string;
|
||||
role: PairedTurnRecord['role'];
|
||||
intentKind: PairedTurnRecord['intent_kind'];
|
||||
state: PairedTurnRecord['state'];
|
||||
attemptNo: number;
|
||||
executorServiceId: string | null;
|
||||
executorAgentType: PairedTurnRecord['executor_agent_type'];
|
||||
activeRunId: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
completedAt: string | null;
|
||||
lastError: string | null;
|
||||
}
|
||||
|
||||
export interface WebDashboardRoomTurnOutput {
|
||||
id: number;
|
||||
turnNumber: number;
|
||||
role: PairedTurnOutput['role'];
|
||||
verdict: PairedTurnOutput['verdict'] | null;
|
||||
createdAt: string;
|
||||
outputText: string;
|
||||
}
|
||||
|
||||
export interface WebDashboardRoomActivity {
|
||||
serviceId: string;
|
||||
jid: string;
|
||||
name: string;
|
||||
folder: string;
|
||||
agentType: StatusSnapshot['agentType'];
|
||||
status: StatusSnapshot['entries'][number]['status'];
|
||||
elapsedMs: number | null;
|
||||
pendingMessages: boolean;
|
||||
pendingTasks: number;
|
||||
messages: WebDashboardRoomMessage[];
|
||||
pairedTask: {
|
||||
id: string;
|
||||
title: string | null;
|
||||
status: PairedTask['status'];
|
||||
roundTripCount: number;
|
||||
updatedAt: string;
|
||||
currentTurn: WebDashboardRoomTurn | null;
|
||||
outputs: WebDashboardRoomTurnOutput[];
|
||||
} | null;
|
||||
}
|
||||
|
||||
export type InboxItemKind =
|
||||
| 'pending-room'
|
||||
| 'reviewer-request'
|
||||
@@ -91,6 +154,8 @@ const SECRET_ASSIGNMENT_RE =
|
||||
/\b([A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|API_KEY|AUTH|PRIVATE_KEY)[A-Z0-9_]*)\s*=\s*([^\s"'`]+)/gi;
|
||||
const SECRET_VALUE_RE =
|
||||
/\b(?:sk-[A-Za-z0-9_-]{12,}|gh[pousr]_[A-Za-z0-9_]{12,}|xox[baprs]-[A-Za-z0-9-]{12,}|eyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,})\b/g;
|
||||
const ROOM_MESSAGE_PREVIEW_MAX_LENGTH = 900;
|
||||
const ROOM_OUTPUT_PREVIEW_MAX_LENGTH = 1800;
|
||||
|
||||
function redactSensitiveText(value: string): string {
|
||||
return value
|
||||
@@ -111,6 +176,10 @@ function buildInboxPreview(value: string): string {
|
||||
return truncateText(redactSensitiveText(value).replace(/\s+/g, ' ').trim());
|
||||
}
|
||||
|
||||
function buildRoomPreview(value: string, maxLength: number): string {
|
||||
return truncateText(redactSensitiveText(value).trim(), maxLength);
|
||||
}
|
||||
|
||||
function stableHash(value: string): string {
|
||||
let hash = 0;
|
||||
for (let index = 0; index < value.length; index += 1) {
|
||||
@@ -334,6 +403,117 @@ export function sanitizeScheduledTask(
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizeRoomMessage(message: NewMessage): WebDashboardRoomMessage {
|
||||
return {
|
||||
id: message.id,
|
||||
sender: message.sender,
|
||||
senderName: message.sender_name || message.sender,
|
||||
content: buildRoomPreview(
|
||||
message.content ?? '',
|
||||
ROOM_MESSAGE_PREVIEW_MAX_LENGTH,
|
||||
),
|
||||
timestamp: message.timestamp,
|
||||
isFromMe: !!message.is_from_me,
|
||||
isBotMessage: !!message.is_bot_message,
|
||||
sourceKind: message.message_source_kind ?? 'human',
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizeRoomTurn(
|
||||
turn: PairedTurnRecord,
|
||||
attempt: PairedTurnAttemptRecord | null,
|
||||
): WebDashboardRoomTurn {
|
||||
return {
|
||||
turnId: turn.turn_id,
|
||||
role: attempt?.role ?? turn.role,
|
||||
intentKind: attempt?.intent_kind ?? turn.intent_kind,
|
||||
state: attempt?.state ?? turn.state,
|
||||
attemptNo: attempt?.attempt_no ?? turn.attempt_no,
|
||||
executorServiceId: attempt?.executor_service_id ?? turn.executor_service_id,
|
||||
executorAgentType: attempt?.executor_agent_type ?? turn.executor_agent_type,
|
||||
activeRunId: attempt?.active_run_id ?? null,
|
||||
createdAt: attempt?.created_at ?? turn.created_at,
|
||||
updatedAt: attempt?.updated_at ?? turn.updated_at,
|
||||
completedAt: attempt?.completed_at ?? turn.completed_at,
|
||||
lastError:
|
||||
(attempt?.last_error ?? turn.last_error)
|
||||
? buildRoomPreview(
|
||||
attempt?.last_error ?? turn.last_error ?? '',
|
||||
ROOM_MESSAGE_PREVIEW_MAX_LENGTH,
|
||||
)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizeRoomTurnOutput(
|
||||
output: PairedTurnOutput,
|
||||
): WebDashboardRoomTurnOutput {
|
||||
return {
|
||||
id: output.id,
|
||||
turnNumber: output.turn_number,
|
||||
role: output.role,
|
||||
verdict: output.verdict ?? null,
|
||||
createdAt: output.created_at,
|
||||
outputText: buildRoomPreview(
|
||||
output.output_text,
|
||||
ROOM_OUTPUT_PREVIEW_MAX_LENGTH,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildWebDashboardRoomActivity(args: {
|
||||
serviceId: string;
|
||||
entry: StatusSnapshot['entries'][number];
|
||||
pairedTask: PairedTask | null;
|
||||
turns: PairedTurnRecord[];
|
||||
attempts: PairedTurnAttemptRecord[];
|
||||
outputs: PairedTurnOutput[];
|
||||
messages: NewMessage[];
|
||||
outputLimit?: number;
|
||||
}): WebDashboardRoomActivity {
|
||||
const latestAttemptByTurnId = new Map<string, PairedTurnAttemptRecord>();
|
||||
for (const attempt of args.attempts) {
|
||||
const previous = latestAttemptByTurnId.get(attempt.turn_id);
|
||||
if (!previous || attempt.attempt_no > previous.attempt_no) {
|
||||
latestAttemptByTurnId.set(attempt.turn_id, attempt);
|
||||
}
|
||||
}
|
||||
const currentTurn =
|
||||
[...args.turns].sort((a, b) =>
|
||||
b.updated_at.localeCompare(a.updated_at),
|
||||
)[0] ?? null;
|
||||
const currentAttempt = currentTurn
|
||||
? (latestAttemptByTurnId.get(currentTurn.turn_id) ?? null)
|
||||
: null;
|
||||
const outputLimit = args.outputLimit ?? 4;
|
||||
|
||||
return {
|
||||
serviceId: args.serviceId,
|
||||
jid: args.entry.jid,
|
||||
name: args.entry.name,
|
||||
folder: args.entry.folder,
|
||||
agentType: args.entry.agentType,
|
||||
status: args.entry.status,
|
||||
elapsedMs: args.entry.elapsedMs,
|
||||
pendingMessages: args.entry.pendingMessages,
|
||||
pendingTasks: args.entry.pendingTasks,
|
||||
messages: args.messages.map(sanitizeRoomMessage),
|
||||
pairedTask: args.pairedTask
|
||||
? {
|
||||
id: args.pairedTask.id,
|
||||
title: args.pairedTask.title,
|
||||
status: args.pairedTask.status,
|
||||
roundTripCount: args.pairedTask.round_trip_count,
|
||||
updatedAt: args.pairedTask.updated_at,
|
||||
currentTurn: currentTurn
|
||||
? sanitizeRoomTurn(currentTurn, currentAttempt)
|
||||
: null,
|
||||
outputs: args.outputs.slice(-outputLimit).map(sanitizeRoomTurnOutput),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildWebDashboardOverview(args: {
|
||||
now?: string;
|
||||
snapshots: StatusSnapshot[];
|
||||
|
||||
@@ -5,9 +5,11 @@ import path from 'path';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import type { StatusSnapshot } from './status-dashboard.js';
|
||||
import type { PairedTurnAttemptRecord, PairedTurnRecord } from './db.js';
|
||||
import type {
|
||||
NewMessage,
|
||||
PairedTask,
|
||||
PairedTurnOutput,
|
||||
RegisteredGroup,
|
||||
ScheduledTask,
|
||||
} from './types.js';
|
||||
@@ -1432,6 +1434,164 @@ describe('web dashboard server handler', () => {
|
||||
expect(response.status).toBe(503);
|
||||
});
|
||||
|
||||
it('serves room timeline with paired turn progress and recent messages', async () => {
|
||||
const pairedTask = makePairedTask({
|
||||
id: 'paired-room-1',
|
||||
chat_jid: 'dc:ops',
|
||||
group_folder: 'ops-room',
|
||||
status: 'in_review',
|
||||
round_trip_count: 2,
|
||||
updated_at: '2026-04-26T05:20:00.000Z',
|
||||
});
|
||||
const turns: PairedTurnRecord[] = [
|
||||
{
|
||||
turn_id: 'paired-room-1:reviewer-turn',
|
||||
task_id: pairedTask.id,
|
||||
task_updated_at: pairedTask.updated_at,
|
||||
role: 'reviewer',
|
||||
intent_kind: 'reviewer-turn',
|
||||
state: 'queued',
|
||||
executor_service_id: null,
|
||||
executor_agent_type: null,
|
||||
attempt_no: 0,
|
||||
created_at: '2026-04-26T05:18:30.000Z',
|
||||
updated_at: '2026-04-26T05:21:00.000Z',
|
||||
completed_at: null,
|
||||
last_error: null,
|
||||
},
|
||||
];
|
||||
const attempts: PairedTurnAttemptRecord[] = [
|
||||
{
|
||||
attempt_id: 'paired-room-1:reviewer-turn:attempt:2',
|
||||
parent_attempt_id: null,
|
||||
parent_handoff_id: null,
|
||||
continuation_handoff_id: null,
|
||||
turn_id: 'paired-room-1:reviewer-turn',
|
||||
task_id: pairedTask.id,
|
||||
task_updated_at: pairedTask.updated_at,
|
||||
role: 'reviewer',
|
||||
intent_kind: 'reviewer-turn',
|
||||
state: 'running',
|
||||
executor_service_id: 'claude-reviewer',
|
||||
executor_agent_type: 'claude-code',
|
||||
active_run_id: 'run-reviewer-1',
|
||||
attempt_no: 2,
|
||||
created_at: '2026-04-26T05:19:00.000Z',
|
||||
updated_at: '2026-04-26T05:21:00.000Z',
|
||||
completed_at: null,
|
||||
last_error: 'OPENAI_API_KEY=plain-secret-value',
|
||||
},
|
||||
];
|
||||
const outputs: PairedTurnOutput[] = [
|
||||
{
|
||||
id: 1,
|
||||
task_id: pairedTask.id,
|
||||
turn_number: 1,
|
||||
role: 'owner',
|
||||
output_text: 'owner final output',
|
||||
verdict: 'step_done',
|
||||
created_at: '2026-04-26T05:18:00.000Z',
|
||||
},
|
||||
];
|
||||
const messages: NewMessage[] = [
|
||||
{
|
||||
id: 'msg-1',
|
||||
chat_jid: 'dc:ops',
|
||||
sender: 'u1',
|
||||
sender_name: '눈쟁이',
|
||||
content: '진행 어디까지야? BOT_TOKEN=plain-secret-value',
|
||||
timestamp: '2026-04-26T05:17:00.000Z',
|
||||
is_from_me: false,
|
||||
is_bot_message: false,
|
||||
message_source_kind: 'human',
|
||||
},
|
||||
];
|
||||
const handler = createWebDashboardHandler({
|
||||
readStatusSnapshots: () => [
|
||||
{
|
||||
serviceId: 'codex-main',
|
||||
agentType: 'codex',
|
||||
assistantName: 'Codex',
|
||||
updatedAt: '2026-04-26T05:22:00.000Z',
|
||||
entries: [
|
||||
{
|
||||
jid: 'dc:ops',
|
||||
name: '#ops',
|
||||
folder: 'ops-room',
|
||||
agentType: 'codex',
|
||||
status: 'processing',
|
||||
elapsedMs: 120_000,
|
||||
pendingMessages: true,
|
||||
pendingTasks: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
getTasks: () => [],
|
||||
getPairedTasks: () => [pairedTask],
|
||||
getLatestPairedTaskForChat: () => pairedTask,
|
||||
getPairedTurnsForTask: (taskId) =>
|
||||
taskId === pairedTask.id ? turns : [],
|
||||
getPairedTurnAttempts: (turnId) =>
|
||||
turnId === turns[0]!.turn_id ? attempts : [],
|
||||
getPairedTurnOutputs: () => outputs,
|
||||
getRecentChatMessages: () => messages,
|
||||
});
|
||||
|
||||
const response = await handler(
|
||||
new Request(
|
||||
`http://localhost/api/rooms/${encodeURIComponent('dc:ops')}/timeline`,
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
const body = (await response.json()) as {
|
||||
jid: string;
|
||||
pairedTask: {
|
||||
id: string;
|
||||
roundTripCount: number;
|
||||
currentTurn: {
|
||||
role: string;
|
||||
state: string;
|
||||
attemptNo: number;
|
||||
lastError: string;
|
||||
};
|
||||
outputs: Array<{ outputText: string; turnNumber: number }>;
|
||||
};
|
||||
messages: Array<{ content: string; senderName: string }>;
|
||||
};
|
||||
expect(body.jid).toBe('dc:ops');
|
||||
expect(body.pairedTask.id).toBe('paired-room-1');
|
||||
expect(body.pairedTask.roundTripCount).toBe(2);
|
||||
expect(body.pairedTask.currentTurn).toMatchObject({
|
||||
role: 'reviewer',
|
||||
state: 'running',
|
||||
attemptNo: 2,
|
||||
lastError: 'OPENAI_API_KEY=<redacted>',
|
||||
});
|
||||
expect(body.pairedTask.outputs).toMatchObject([
|
||||
{ turnNumber: 1, outputText: 'owner final output' },
|
||||
]);
|
||||
expect(body.messages[0]?.content).toContain('BOT_TOKEN=<redacted>');
|
||||
expect(body.messages[0]?.senderName).toBe('눈쟁이');
|
||||
});
|
||||
|
||||
it('returns 404 for missing room timelines', async () => {
|
||||
const handler = createWebDashboardHandler({
|
||||
readStatusSnapshots: () => [],
|
||||
getTasks: () => [],
|
||||
getPairedTasks: () => [],
|
||||
});
|
||||
|
||||
const response = await handler(
|
||||
new Request(
|
||||
`http://localhost/api/rooms/${encodeURIComponent('dc:missing')}/timeline`,
|
||||
),
|
||||
);
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it('serves Vite static assets and falls back to index for SPA routes', async () => {
|
||||
const staticDir = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), 'ejclaw-dashboard-'),
|
||||
|
||||
@@ -10,7 +10,12 @@ import {
|
||||
deleteTask,
|
||||
getAllOpenPairedTasks,
|
||||
getAllTasks,
|
||||
getLatestPairedTaskForChat,
|
||||
getPairedTaskById,
|
||||
getPairedTurnAttempts,
|
||||
getPairedTurnOutputs,
|
||||
getPairedTurnsForTask,
|
||||
getRecentChatMessages,
|
||||
getTaskById,
|
||||
hasMessage,
|
||||
storeChatMetadata,
|
||||
@@ -34,6 +39,7 @@ import type {
|
||||
} from './types.js';
|
||||
import { isWatchCiTask } from './task-watch-status.js';
|
||||
import {
|
||||
buildWebDashboardRoomActivity,
|
||||
buildWebDashboardOverview,
|
||||
sanitizeScheduledTask,
|
||||
} from './web-dashboard-data.js';
|
||||
@@ -106,6 +112,11 @@ export interface WebDashboardHandlerOptions {
|
||||
}) => void;
|
||||
deleteTask?: (id: string) => void;
|
||||
getPairedTasks?: () => PairedTask[];
|
||||
getLatestPairedTaskForChat?: (chatJid: string) => PairedTask | undefined;
|
||||
getPairedTurnsForTask?: typeof getPairedTurnsForTask;
|
||||
getPairedTurnAttempts?: typeof getPairedTurnAttempts;
|
||||
getPairedTurnOutputs?: typeof getPairedTurnOutputs;
|
||||
getRecentChatMessages?: typeof getRecentChatMessages;
|
||||
getPairedTaskById?: (id: string) => PairedTask | undefined;
|
||||
updatePairedTaskIfUnchanged?: (
|
||||
id: string,
|
||||
@@ -265,6 +276,16 @@ function parseRoomMessagePath(pathname: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
function parseRoomTimelinePath(pathname: string): string | null {
|
||||
const match = pathname.match(/^\/api\/rooms\/([^/]+)\/timeline$/);
|
||||
if (!match) return null;
|
||||
try {
|
||||
return decodeURIComponent(match[1]);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function parseServiceActionPath(pathname: string): string | null {
|
||||
const match = pathname.match(/^\/api\/services\/([^/]+)\/actions$/);
|
||||
if (!match) return null;
|
||||
@@ -648,6 +669,16 @@ export function createWebDashboardHandler(
|
||||
const loadPairedTaskById = opts.getPairedTaskById ?? getPairedTaskById;
|
||||
const mutatePairedTaskIfUnchanged =
|
||||
opts.updatePairedTaskIfUnchanged ?? updatePairedTaskIfUnchanged;
|
||||
const loadLatestPairedTaskForChat =
|
||||
opts.getLatestPairedTaskForChat ?? getLatestPairedTaskForChat;
|
||||
const loadPairedTurnsForTask =
|
||||
opts.getPairedTurnsForTask ?? getPairedTurnsForTask;
|
||||
const loadPairedTurnOutputs =
|
||||
opts.getPairedTurnOutputs ?? getPairedTurnOutputs;
|
||||
const loadPairedTurnAttempts =
|
||||
opts.getPairedTurnAttempts ?? getPairedTurnAttempts;
|
||||
const loadRecentChatMessages =
|
||||
opts.getRecentChatMessages ?? getRecentChatMessages;
|
||||
const schedulePairedFollowUp =
|
||||
opts.schedulePairedFollowUp ?? schedulePairedFollowUpIntent;
|
||||
const loadRoomBindings = opts.getRoomBindings;
|
||||
@@ -699,6 +730,7 @@ export function createWebDashboardHandler(
|
||||
const taskId = parseTaskPath(url.pathname);
|
||||
const actionInboxId = parseInboxActionPath(url.pathname);
|
||||
const messageRoomJid = parseRoomMessagePath(url.pathname);
|
||||
const timelineRoomJid = parseRoomTimelinePath(url.pathname);
|
||||
const actionServiceId = parseServiceActionPath(url.pathname);
|
||||
|
||||
if (actionTaskId) {
|
||||
@@ -949,6 +981,47 @@ export function createWebDashboardHandler(
|
||||
return jsonResponse({ ok: true, id, queued: true });
|
||||
}
|
||||
|
||||
if (timelineRoomJid) {
|
||||
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
||||
return jsonResponse({ error: 'Method not allowed' }, { status: 405 });
|
||||
}
|
||||
|
||||
const snapshots = readSnapshots(statusMaxAgeMs);
|
||||
const matched = snapshots
|
||||
.flatMap((snapshot) =>
|
||||
snapshot.entries
|
||||
.filter((entry) => entry.jid === timelineRoomJid)
|
||||
.map((entry) => ({ snapshot, entry })),
|
||||
)
|
||||
.sort((a, b) =>
|
||||
b.snapshot.updatedAt.localeCompare(a.snapshot.updatedAt),
|
||||
)
|
||||
.at(0);
|
||||
if (!matched) {
|
||||
return jsonResponse(
|
||||
{ error: 'Room timeline not found' },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
|
||||
const pairedTask = loadLatestPairedTaskForChat(timelineRoomJid) ?? null;
|
||||
const turns = pairedTask ? loadPairedTurnsForTask(pairedTask.id) : [];
|
||||
const attempts = turns.flatMap((turn) =>
|
||||
loadPairedTurnAttempts(turn.turn_id),
|
||||
);
|
||||
return jsonResponse(
|
||||
buildWebDashboardRoomActivity({
|
||||
serviceId: matched.snapshot.serviceId,
|
||||
entry: matched.entry,
|
||||
pairedTask,
|
||||
turns,
|
||||
attempts,
|
||||
outputs: pairedTask ? loadPairedTurnOutputs(pairedTask.id) : [],
|
||||
messages: loadRecentChatMessages(timelineRoomJid, 8),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (actionServiceId) {
|
||||
if (request.method !== 'POST') {
|
||||
return jsonResponse({ error: 'Method not allowed' }, { status: 405 });
|
||||
|
||||
Reference in New Issue
Block a user