mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-12-04 21:05:24 +00:00
fix: keep the agent's question and the user's answer in the chat (#2110)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Pre-commit / pre-commit (push) Waiting to run
Test / Run Web + Local Brain Smoke (push) Waiting to run
Test / Run Frontend Guardrails (push) Waiting to run
Test / Run Browser Preview Electron Test (push) Waiting to run
Test / Run Python Tests (push) Waiting to run
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Pre-commit / pre-commit (push) Waiting to run
Test / Run Web + Local Brain Smoke (push) Waiting to run
Test / Run Frontend Guardrails (push) Waiting to run
Test / Run Browser Preview Electron Test (push) Waiting to run
Test / Run Python Tests (push) Waiting to run
This commit is contained in:
parent
a46f680ea2
commit
0af2a57ab5
11 changed files with 412 additions and 42 deletions
|
|
@ -921,7 +921,8 @@ function safeHumanResponse(
|
|||
*/
|
||||
export function injectHumanInputReceipts(
|
||||
entries: GroupedEntry[],
|
||||
messages: HumanControlMessage[]
|
||||
messages: HumanControlMessage[],
|
||||
resolvedInteractionIds: readonly string[] = []
|
||||
): GroupedEntry[] {
|
||||
const asks = messages
|
||||
.map((message, index) => ({ message, index }))
|
||||
|
|
@ -970,6 +971,12 @@ export function injectHumanInputReceipts(
|
|||
? adjacent
|
||||
: undefined;
|
||||
const response = explicitlyCorrelated || adjacentReply;
|
||||
// A question cancelled or expired without an answer (for example at
|
||||
// Resume) keeps its tool position but shows no receipt.
|
||||
const closedUnanswered =
|
||||
Boolean(
|
||||
interactionId && resolvedInteractionIds.includes(interactionId)
|
||||
) && !response;
|
||||
const requestedBy = normalizedAgentIdentity(
|
||||
ask.agent_name || ask.interaction?.agent
|
||||
);
|
||||
|
|
@ -990,7 +997,7 @@ export function injectHumanInputReceipts(
|
|||
if (toolIndex !== -1) {
|
||||
const [{ entryIndex, itemIndex }] = unusedHumanTools.splice(toolIndex, 1);
|
||||
const tool = result[entryIndex]!.items[itemIndex];
|
||||
if (tool?.kind === 'tool') {
|
||||
if (tool?.kind === 'tool' && !closedUnanswered) {
|
||||
result[entryIndex]!.items[itemIndex] = {
|
||||
...tool,
|
||||
humanInput: receipt,
|
||||
|
|
@ -998,6 +1005,7 @@ export function injectHumanInputReceipts(
|
|||
}
|
||||
continue;
|
||||
}
|
||||
if (closedUnanswered) continue;
|
||||
|
||||
// Compatibility fallback for old histories where toolkit logs were
|
||||
// filtered out: retain the receipt in the matching agent's work log.
|
||||
|
|
@ -1124,7 +1132,8 @@ function useTaskWorkStoreSnapshot(
|
|||
`${message.id}:${message.step ?? ''}:${message.interaction?.interaction_id ?? ''}:${message.interactionResponseTo ?? ''}:${message.content}`
|
||||
)
|
||||
.join('>');
|
||||
return `${t.status}|${t.durableRunStatus ?? ''}|${t.taskTime}|${t.elapsed}|${logDigest}|${activeFormDigest}|${humanInputDigest}`;
|
||||
const resolvedDigest = (t.resolvedInteractionIds ?? []).join('>');
|
||||
return `${t.status}|${t.durableRunStatus ?? ''}|${t.taskTime}|${t.elapsed}|${logDigest}|${activeFormDigest}|${humanInputDigest}|${resolvedDigest}`;
|
||||
},
|
||||
() => ''
|
||||
);
|
||||
|
|
@ -1145,7 +1154,8 @@ function useTaskWorkLogData(
|
|||
const blocks = buildAgentBlocks(tagged, isSingleAgent);
|
||||
const groups = injectHumanInputReceipts(
|
||||
groupBlocksByAgent(blocks, isSingleAgent),
|
||||
t?.messages ?? []
|
||||
t?.messages ?? [],
|
||||
t?.resolvedInteractionIds
|
||||
);
|
||||
return { task: t, groups };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,22 +143,30 @@ export function groupMessagesByQuery(messages: readonly any[]): QueryGroup[] {
|
|||
if (message.role === 'user') {
|
||||
const previousMessage = messages[index - 1];
|
||||
|
||||
// An explicit ASK is an interruption inside the current Run, not a new
|
||||
// query turn. Structured replies correlate by interaction id; legacy
|
||||
// ASK frames use only strict adjacency so an ordinary follow-up can
|
||||
// never be guessed into a human-input receipt.
|
||||
if (
|
||||
currentGroup &&
|
||||
previousMessage?.role === 'agent' &&
|
||||
previousMessage?.step === AgentStep.ASK &&
|
||||
(!message.interactionResponseTo ||
|
||||
(previousMessage?.interaction?.interaction_id &&
|
||||
message.interactionResponseTo ===
|
||||
previousMessage.interaction.interaction_id))
|
||||
) {
|
||||
currentGroup.interactionResponses = {
|
||||
...currentGroup.interactionResponses,
|
||||
[previousMessage.id]: message,
|
||||
const replyId = message.interactionResponseTo;
|
||||
const askGroup = replyId
|
||||
? [...groups, ...(currentGroup ? [currentGroup] : [])].find((group) =>
|
||||
group.otherMessages.some(
|
||||
(candidate: Message) =>
|
||||
candidate.step === AgentStep.ASK &&
|
||||
candidate.interaction?.interaction_id === replyId
|
||||
)
|
||||
)
|
||||
: previousMessage?.role === 'agent' &&
|
||||
previousMessage.step === AgentStep.ASK
|
||||
? currentGroup
|
||||
: undefined;
|
||||
const ask = replyId
|
||||
? askGroup?.otherMessages.find(
|
||||
(candidate: Message) =>
|
||||
candidate.step === AgentStep.ASK &&
|
||||
candidate.interaction?.interaction_id === replyId
|
||||
)
|
||||
: previousMessage;
|
||||
if (askGroup && ask) {
|
||||
askGroup.interactionResponses = {
|
||||
...askGroup.interactionResponses,
|
||||
[ask.id]: message,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -340,8 +340,9 @@ export const UserQueryGroup: React.FC<UserQueryGroupProps> = ({
|
|||
? chatState.tasks[activeTaskId]
|
||||
: null;
|
||||
const runDisplayStatus = task ? getTaskRunDisplayStatus(task) : undefined;
|
||||
const hasVisibleAgentOutput = queryGroup.otherMessages.some(
|
||||
const hasVisibleAgentOutput = activeTask?.messages.some(
|
||||
(message) =>
|
||||
message?.role === 'agent' &&
|
||||
message?.step !== AgentStep.ASK &&
|
||||
typeof message?.content === 'string' &&
|
||||
message.content.trim().length > 0
|
||||
|
|
@ -353,6 +354,7 @@ export const UserQueryGroup: React.FC<UserQueryGroupProps> = ({
|
|||
failureFacts.finalResponse !== 'present'
|
||||
);
|
||||
const showMissingFinalResponse = Boolean(
|
||||
queryGroup.ownsRunWorkLog &&
|
||||
task?.status === ChatTaskStatus.FINISHED &&
|
||||
activeTask?.durableRunStatus !== 'failed' &&
|
||||
runDisplayStatus &&
|
||||
|
|
|
|||
|
|
@ -25,22 +25,20 @@ export function isUserMessageReplyToAsk(
|
|||
if (userMessageIndex <= 0) return false;
|
||||
|
||||
const userMessage = messages[userMessageIndex];
|
||||
const previousMessage = messages[userMessageIndex - 1];
|
||||
if (
|
||||
userMessage?.role !== 'user' ||
|
||||
previousMessage?.role !== 'agent' ||
|
||||
previousMessage.step !== AgentStep.ASK
|
||||
) {
|
||||
return false;
|
||||
if (userMessage?.role !== 'user') return false;
|
||||
if (userMessage.interactionResponseTo) {
|
||||
return messages.some(
|
||||
(message) =>
|
||||
message.role === 'agent' &&
|
||||
message.step === AgentStep.ASK &&
|
||||
message.interaction?.interaction_id ===
|
||||
userMessage.interactionResponseTo
|
||||
);
|
||||
}
|
||||
|
||||
const askInteractionId = previousMessage.interaction?.interaction_id;
|
||||
return userMessage.interactionResponseTo
|
||||
? Boolean(
|
||||
askInteractionId &&
|
||||
askInteractionId === userMessage.interactionResponseTo
|
||||
)
|
||||
: true;
|
||||
const previousMessage = messages[userMessageIndex - 1];
|
||||
return (
|
||||
previousMessage?.role === 'agent' && previousMessage.step === AgentStep.ASK
|
||||
);
|
||||
}
|
||||
|
||||
/** Interaction IDs answered by explicit correlation or direct adjacency. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
import { AgentStep } from '@/types/constants';
|
||||
|
||||
export interface TaskDurationState {
|
||||
taskTime: number;
|
||||
elapsed: number;
|
||||
|
|
@ -66,3 +68,36 @@ export function resolveHistoricalRunElapsedMs({
|
|||
}
|
||||
return Math.max(0, epochToMs(updatedAt) - epochToMs(createdAt));
|
||||
}
|
||||
|
||||
/**
|
||||
* Track the time a played-back Run spent waiting for the user.
|
||||
*
|
||||
* Playback measures a Run by the span of its recorded steps, which includes
|
||||
* every wait for an answer or approval. A request opens a wait at its first
|
||||
* recorded step (the journal can carry the same request twice) and its first
|
||||
* recorded outcome closes it. Overlapping waits count once; a wait still open
|
||||
* when playback ends is not counted.
|
||||
*/
|
||||
export function createPlaybackUserWaitTracker() {
|
||||
const open = new Set<string>();
|
||||
const closed = new Set<string>();
|
||||
let waitingSinceMs: number | null = null;
|
||||
let waitedMs = 0;
|
||||
return {
|
||||
observe(step: unknown, interactionId: unknown, atMs: number) {
|
||||
if (typeof interactionId !== 'string' || !interactionId) return;
|
||||
if (closed.has(interactionId)) return;
|
||||
if (step === AgentStep.ASK && !open.has(interactionId)) {
|
||||
if (open.size === 0) waitingSinceMs = atMs;
|
||||
open.add(interactionId);
|
||||
} else if (step === AgentStep.HUMAN_REPLY && open.delete(interactionId)) {
|
||||
closed.add(interactionId);
|
||||
if (open.size === 0 && waitingSinceMs !== null) {
|
||||
waitedMs += Math.max(0, atMs - waitingSinceMs);
|
||||
waitingSinceMs = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
waitedMs: () => waitedMs,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,10 @@ import {
|
|||
type ResolvedSpaceModel,
|
||||
type SpaceModelSelection,
|
||||
} from '@/lib/spaceModelBinding';
|
||||
import { settleTaskElapsedMs } from '@/lib/taskDuration';
|
||||
import {
|
||||
createPlaybackUserWaitTracker,
|
||||
settleTaskElapsedMs,
|
||||
} from '@/lib/taskDuration';
|
||||
import {
|
||||
classifyError as classifyUsageError,
|
||||
errorCopy,
|
||||
|
|
@ -207,11 +210,37 @@ export const canonicalRunEventToLegacyMessage = (
|
|||
if (!value || typeof value !== 'object') return null;
|
||||
const event = value as {
|
||||
event_id?: unknown;
|
||||
run_id?: unknown;
|
||||
event_type?: unknown;
|
||||
legacy_step?: unknown;
|
||||
payload?: unknown;
|
||||
created_at?: unknown;
|
||||
};
|
||||
if (event.event_type === 'interaction.requested') {
|
||||
const payload = event.payload as Record<string, unknown> | undefined;
|
||||
const request = payload?.request;
|
||||
// Only a question is fully described by its request. Other types keep
|
||||
// options, schema or display arguments outside it, so their legacy ASK
|
||||
// frame stays the source.
|
||||
if (
|
||||
typeof payload?.interaction_id !== 'string' ||
|
||||
payload.interaction_type !== 'question' ||
|
||||
!request ||
|
||||
typeof request !== 'object'
|
||||
)
|
||||
return null;
|
||||
return {
|
||||
step: AgentStep.ASK,
|
||||
data: {
|
||||
...request,
|
||||
interaction_id: payload.interaction_id,
|
||||
interaction_type: payload.interaction_type,
|
||||
run_id: event.run_id,
|
||||
},
|
||||
timestamp:
|
||||
typeof event.created_at === 'number' ? event.created_at : undefined,
|
||||
} as AgentMessage;
|
||||
}
|
||||
// Interaction outcomes are canonical-only events: a decision, a system
|
||||
// cancellation (for example at restart) or an expiry. Project the durable
|
||||
// interaction id into the legacy reducer so reconnect/replay closes the
|
||||
|
|
@ -321,10 +350,15 @@ export const canonicalRunEventToLegacyMessage = (
|
|||
/** Remove only the card resolved by a durable interaction decision. */
|
||||
export function removeResolvedInteractionMessages(
|
||||
messages: Message[],
|
||||
interactionId: string
|
||||
interactionId: string,
|
||||
preserveQuestions = false
|
||||
): Message[] {
|
||||
return messages.filter(
|
||||
(message) => message.interaction?.interaction_id !== interactionId
|
||||
(message) =>
|
||||
message.interaction?.interaction_id !== interactionId ||
|
||||
(preserveQuestions &&
|
||||
message.step === AgentStep.ASK &&
|
||||
message.interaction?.interaction_type === 'question')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -3261,6 +3295,7 @@ const chatStore = (initial?: Partial<ChatStore>) =>
|
|||
let skipFirstConfirm = true;
|
||||
let playbackFirstStepTimeMs: number | null = null;
|
||||
let playbackLastStepTimeMs: number | null = null;
|
||||
const playbackUserWaits = createPlaybackUserWaitTracker();
|
||||
let localDurableLegacyEventCount = 0;
|
||||
|
||||
// replay or share request
|
||||
|
|
@ -4904,6 +4939,11 @@ const chatStore = (initial?: Partial<ChatStore>) =>
|
|||
if (stepTimeMs !== null) {
|
||||
playbackFirstStepTimeMs ??= stepTimeMs;
|
||||
playbackLastStepTimeMs = stepTimeMs;
|
||||
playbackUserWaits.observe(
|
||||
agentMessages?.step,
|
||||
agentMessages?.data?.interaction_id,
|
||||
stepTimeMs
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -6772,7 +6812,9 @@ const chatStore = (initial?: Partial<ChatStore>) =>
|
|||
playbackLastStepTimeMs !== null
|
||||
? Math.max(
|
||||
0,
|
||||
playbackLastStepTimeMs - playbackFirstStepTimeMs
|
||||
playbackLastStepTimeMs -
|
||||
playbackFirstStepTimeMs -
|
||||
playbackUserWaits.waitedMs()
|
||||
)
|
||||
: null;
|
||||
const settledElapsed =
|
||||
|
|
@ -7134,7 +7176,12 @@ const chatStore = (initial?: Partial<ChatStore>) =>
|
|||
!replayCaughtUp &&
|
||||
playbackFirstStepTimeMs !== null &&
|
||||
playbackLastStepTimeMs !== null
|
||||
? Math.max(0, playbackLastStepTimeMs - playbackFirstStepTimeMs)
|
||||
? Math.max(
|
||||
0,
|
||||
playbackLastStepTimeMs -
|
||||
playbackFirstStepTimeMs -
|
||||
playbackUserWaits.waitedMs()
|
||||
)
|
||||
: null;
|
||||
if (playbackElapsed !== null) {
|
||||
completedElapsed = playbackElapsed;
|
||||
|
|
@ -8071,7 +8118,8 @@ const chatStore = (initial?: Partial<ChatStore>) =>
|
|||
const alreadyResolved = resolvedInteractionIds.includes(interactionId);
|
||||
const messages = removeResolvedInteractionMessages(
|
||||
task.messages,
|
||||
interactionId
|
||||
interactionId,
|
||||
true
|
||||
);
|
||||
const askList = removeResolvedInteractionMessages(
|
||||
task.askList,
|
||||
|
|
|
|||
|
|
@ -58,6 +58,32 @@ const structuredAsk = (id: string, question: string) => ({
|
|||
});
|
||||
|
||||
describe('legacy Run query grouping', () => {
|
||||
it('keeps non-adjacent correlated replies with their question after completion', () => {
|
||||
const prompt = userMessage('prompt', 'Save my colour');
|
||||
const ask = structuredAsk('ask', 'Which colour?');
|
||||
const reply = {
|
||||
...userMessage('reply', 'teal'),
|
||||
interactionResponseTo: 'interaction-ask',
|
||||
};
|
||||
const messages = [
|
||||
prompt,
|
||||
ask,
|
||||
{
|
||||
id: 'tool',
|
||||
role: 'agent',
|
||||
step: AgentStep.ACTIVATE_TOOLKIT,
|
||||
content: '',
|
||||
},
|
||||
reply,
|
||||
{ id: 'final', role: 'agent', step: AgentStep.END, content: 'Done' },
|
||||
];
|
||||
const groups = groupMessagesByQuery(messages);
|
||||
expect(groups).toHaveLength(1);
|
||||
expect(groups[0].interactionResponses?.ask).toEqual(reply);
|
||||
expect(groups[0].otherMessages.at(-1)?.content).toBe('Done');
|
||||
expect(isUserMessageReplyToAsk(messages as Message[], 'reply')).toBe(true);
|
||||
});
|
||||
|
||||
it.each([true, false])(
|
||||
'renders retained legacy evidence without extra main entries (canonical: %s)',
|
||||
(canonical) => {
|
||||
|
|
|
|||
|
|
@ -253,6 +253,55 @@ describe('UserQueryGroup Run work-log ownership', () => {
|
|||
expect(screen.queryByText('Europe')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('leaves an answered question to the work log after the Run completes', () => {
|
||||
const prompt = { id: 'user-1', role: 'user', content: 'Build a report' };
|
||||
const ask = {
|
||||
id: 'ask-1',
|
||||
role: 'agent',
|
||||
step: AgentStep.ASK,
|
||||
content: 'Which region?',
|
||||
interaction: {
|
||||
interaction_id: 'interaction-1',
|
||||
interaction_type: 'question',
|
||||
run_id: 'run-1',
|
||||
question: 'Which region?',
|
||||
},
|
||||
};
|
||||
const tool = {
|
||||
id: 'tool-1',
|
||||
role: 'agent',
|
||||
step: AgentStep.ACTIVATE_TOOLKIT,
|
||||
content: '',
|
||||
};
|
||||
const reply = {
|
||||
id: 'reply-1',
|
||||
role: 'user',
|
||||
content: 'Europe',
|
||||
interactionResponseTo: 'interaction-1',
|
||||
};
|
||||
const end = {
|
||||
id: 'end-1',
|
||||
role: 'agent',
|
||||
step: AgentStep.END,
|
||||
content: 'Done',
|
||||
};
|
||||
|
||||
renderGroups([prompt, ask, tool, reply, end], {
|
||||
status: ChatTaskStatus.FINISHED,
|
||||
durableRunStatus: 'completed',
|
||||
activeAsk: '',
|
||||
resolvedInteractionIds: ['interaction-1'],
|
||||
});
|
||||
|
||||
expect(screen.getAllByTestId('task-work-log')).toHaveLength(1);
|
||||
expect(screen.queryByText('Which region?')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('Europe')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Done')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText('This task ended before Eigent sent a final reply.')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('forwards message lifecycle and Run identity to every feedback card path', () => {
|
||||
const messages = [
|
||||
{ id: 'user-1', role: 'user', content: 'Build a report' },
|
||||
|
|
|
|||
|
|
@ -700,6 +700,98 @@ describe('injectHumanInputReceipts permission approvals', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('injectHumanInputReceipts question history', () => {
|
||||
const humanTool = (id: string) =>
|
||||
makeToolItem(id, {
|
||||
rowTitle: 'Human Toolkit · Ask human via gui',
|
||||
toolkitName: 'Human Toolkit',
|
||||
method: 'Ask human via gui',
|
||||
});
|
||||
const question = (id: string, text: string): Message => ({
|
||||
id: `ask-${id}`,
|
||||
role: 'agent',
|
||||
content: text,
|
||||
step: AgentStep.ASK,
|
||||
agent_name: 'single_agent',
|
||||
interaction: {
|
||||
interaction_id: id,
|
||||
interaction_type: 'question',
|
||||
run_id: 'task-1',
|
||||
question: text,
|
||||
},
|
||||
});
|
||||
|
||||
it('keeps an answered question after Resume and drops the cancelled one', () => {
|
||||
const tools = [humanTool('cancelled-call'), humanTool('answered-call')];
|
||||
const group: AgentGroup = {
|
||||
kind: 'agent-group',
|
||||
id: 'group-single-agent',
|
||||
agentId: 'single-agent',
|
||||
agentType: 'single_agent',
|
||||
agentName: 'single_agent',
|
||||
items: tools,
|
||||
status: 'done',
|
||||
doneToolCount: tools.length,
|
||||
totalToolCount: tools.length,
|
||||
};
|
||||
const messages: Message[] = [
|
||||
{ id: 'prompt', role: 'user', content: 'Save my colour' },
|
||||
question('cancelled', 'Which colour?'),
|
||||
question('answered', 'Which colour?'),
|
||||
{
|
||||
id: 'tool-step',
|
||||
role: 'agent',
|
||||
content: '',
|
||||
step: AgentStep.ACTIVATE_TOOLKIT,
|
||||
},
|
||||
{
|
||||
id: 'reply',
|
||||
role: 'user',
|
||||
content: 'teal',
|
||||
interactionResponseTo: 'answered',
|
||||
},
|
||||
];
|
||||
|
||||
const [result] = injectHumanInputReceipts([group], messages, [
|
||||
'cancelled',
|
||||
'answered',
|
||||
]);
|
||||
const items = result!.items as Array<{
|
||||
humanInput?: { response?: string };
|
||||
}>;
|
||||
|
||||
expect(items[0]?.humanInput).toBeUndefined();
|
||||
expect(items[1]?.humanInput).toMatchObject({
|
||||
question: 'Which colour?',
|
||||
response: 'teal',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps a pending question without an answer', () => {
|
||||
const group: AgentGroup = {
|
||||
kind: 'agent-group',
|
||||
id: 'group-single-agent',
|
||||
agentId: 'single-agent',
|
||||
agentType: 'single_agent',
|
||||
agentName: 'single_agent',
|
||||
items: [humanTool('pending-call')],
|
||||
status: 'running',
|
||||
doneToolCount: 0,
|
||||
totalToolCount: 1,
|
||||
};
|
||||
|
||||
const [result] = injectHumanInputReceipts(
|
||||
[group],
|
||||
[question('pending', 'Which colour?')],
|
||||
[]
|
||||
);
|
||||
|
||||
expect(
|
||||
(result!.items[0] as { humanInput?: { question?: string } }).humanInput
|
||||
).toMatchObject({ question: 'Which colour?', response: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('terminal Run presentation', () => {
|
||||
it('lets a recorded error override a compatibility interrupted status', () => {
|
||||
expect(
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@
|
|||
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
import {
|
||||
createPlaybackUserWaitTracker,
|
||||
resolveHistoricalRunElapsedMs,
|
||||
settleTaskElapsedMs,
|
||||
} from '@/lib/taskDuration';
|
||||
import { AgentStep } from '@/types/constants';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('settleTaskElapsedMs', () => {
|
||||
|
|
@ -56,3 +58,31 @@ describe('resolveHistoricalRunElapsedMs', () => {
|
|||
expect(resolveHistoricalRunElapsedMs({ createdAt: 123 })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPlaybackUserWaitTracker', () => {
|
||||
it('leaves question and approval waits out of a restored Run', () => {
|
||||
const waits = createPlaybackUserWaitTracker();
|
||||
// Journal order: the request, then its legacy ask frame for the same id.
|
||||
waits.observe(AgentStep.ASK, 'question-1', 4_000);
|
||||
waits.observe(AgentStep.ACTIVATE_TOOLKIT, undefined, 4_100);
|
||||
waits.observe(AgentStep.ASK, 'question-1', 4_200);
|
||||
waits.observe(AgentStep.HUMAN_REPLY, 'question-1', 14_231);
|
||||
waits.observe(AgentStep.HUMAN_REPLY, 'question-1', 14_300);
|
||||
waits.observe(AgentStep.ASK, 'approval:run-1:call-1', 20_000);
|
||||
waits.observe(AgentStep.HUMAN_REPLY, 'approval:run-1:call-1', 36_831);
|
||||
|
||||
expect(waits.waitedMs()).toBe(10_231 + 16_831);
|
||||
});
|
||||
|
||||
it('counts overlapping waits once and ignores a wait still open', () => {
|
||||
const waits = createPlaybackUserWaitTracker();
|
||||
waits.observe(AgentStep.ASK, 'a', 1_000);
|
||||
waits.observe(AgentStep.ASK, 'b', 2_000);
|
||||
waits.observe(AgentStep.HUMAN_REPLY, 'a', 3_000);
|
||||
waits.observe(AgentStep.HUMAN_REPLY, 'b', 5_000);
|
||||
waits.observe(AgentStep.ASK, 'c', 6_000);
|
||||
waits.observe(AgentStep.HUMAN_REPLY, 'unknown', 7_000);
|
||||
|
||||
expect(waits.waitedMs()).toBe(4_000);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import {
|
|||
removeResolvedInteractionMessages,
|
||||
shouldAppendTaskForConfirmedEvent,
|
||||
} from '@/store/chatStore';
|
||||
import { AgentStep } from '@/types/constants';
|
||||
import i18next from 'i18next';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
|
|
@ -663,3 +664,74 @@ describe('canonical Run replay projection', () => {
|
|||
).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('question history projection', () => {
|
||||
it('projects the canonical request without a legacy ASK frame', () => {
|
||||
expect(
|
||||
canonicalRunEventToLegacyMessage({
|
||||
event_type: 'interaction.requested',
|
||||
run_id: 'run-1',
|
||||
created_at: 123,
|
||||
payload: {
|
||||
interaction_id: 'question',
|
||||
interaction_type: 'question',
|
||||
request: { question: 'Which colour?', agent: 'single_agent' },
|
||||
},
|
||||
})
|
||||
).toEqual({
|
||||
step: AgentStep.ASK,
|
||||
timestamp: 123,
|
||||
data: {
|
||||
interaction_id: 'question',
|
||||
interaction_type: 'question',
|
||||
run_id: 'run-1',
|
||||
question: 'Which colour?',
|
||||
agent: 'single_agent',
|
||||
},
|
||||
});
|
||||
});
|
||||
it.each(['memory_change_review', 'merge_conflict'])(
|
||||
'leaves a %s request to its legacy frame',
|
||||
(interactionType) => {
|
||||
expect(
|
||||
canonicalRunEventToLegacyMessage({
|
||||
event_type: 'interaction.requested',
|
||||
run_id: 'run-1',
|
||||
payload: {
|
||||
interaction_id: 'review',
|
||||
interaction_type: interactionType,
|
||||
request: { question: 'Allow this change?' },
|
||||
options: [{ id: 'keep_run', label: 'Keep Run version' }],
|
||||
},
|
||||
})
|
||||
).toBeNull();
|
||||
}
|
||||
);
|
||||
it('retains resolved questions in history while removing their actionable queue entry', () => {
|
||||
const ask = {
|
||||
id: 'ask',
|
||||
role: 'agent',
|
||||
step: AgentStep.ASK,
|
||||
content: 'Colour?',
|
||||
interaction: {
|
||||
interaction_id: 'question',
|
||||
interaction_type: 'question',
|
||||
run_id: 'run-1',
|
||||
},
|
||||
} as Message;
|
||||
const store = createChatStoreInstance();
|
||||
store.getState().create('run-1');
|
||||
store.getState().addMessages('run-1', ask);
|
||||
store.getState().setActiveAskList('run-1', [ask]);
|
||||
store.getState().markHumanInteractionResolved('run-1', 'question');
|
||||
expect(store.getState().tasks['run-1'].messages).toContainEqual(ask);
|
||||
expect(store.getState().tasks['run-1'].askList).toEqual([]);
|
||||
expect(store.getState().tasks['run-1'].resolvedInteractionIds).toEqual([
|
||||
'question',
|
||||
]);
|
||||
expect(removeResolvedInteractionMessages([ask], 'question', true)).toEqual([
|
||||
ask,
|
||||
]);
|
||||
expect(removeResolvedInteractionMessages([ask], 'question')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue