Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/runtime/src/__tests__/runtime-event-read-model.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,6 +288,62 @@ describe('projectRuntimeEventsToStoredMessages', () => {
expect(out.diagnostics.map((diag) => diag.code)).toEqual(['context_remaining_unsupported']);
});

test('projects an AskUserQuestion round trip without a legacy row for the live request', () => {
const out = projectRuntimeEventsToStoredMessages([
ev({
id: 'evt-question-call',
ts: ts + 1,
role: 'model',
author: 'agent',
content: {
kind: 'function_call',
id: 'question-tool-1',
name: 'AskUserQuestion',
args: { questions: [{ question: 'Choose', options: [{ label: 'Extend' }] }] },
},
refs: { toolCallId: 'question-tool-1' },
}),
ev({
id: 'evt-question-request',
ts: ts + 2,
actions: {
userQuestionRequest: {
requestId: 'question-1',
toolUseId: 'question-tool-1',
questions: [{ question: 'Choose', options: [{ label: 'Extend' }] }],
},
},
refs: { toolCallId: 'question-tool-1' },
}),
ev({
id: 'evt-question-result',
ts: ts + 3,
role: 'tool',
author: 'tool',
content: {
kind: 'function_response',
id: 'question-tool-1',
name: 'AskUserQuestion',
result: { kind: 'json', value: { answers: ['Extend'] } },
},
refs: { toolCallId: 'question-tool-1' },
}),
ev({
id: 'evt-question-complete',
ts: ts + 4,
status: 'completed',
actions: { endInvocation: true },
}),
], { runHeaders: [header] });

expect(out.messages.map((message) => message.type)).toEqual([
'tool_call',
'tool_result',
'turn_state',
]);
expect(out.diagnostics).toEqual([]);
});

test('normalizes an exact legacy terminal result at RuntimeEvent restore', () => {
const out = projectRuntimeEventsToStoredMessages([
ev({
Expand Down
6 changes: 6 additions & 0 deletions packages/runtime/src/runtime-event-read-model.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,12 @@ export function projectRuntimeEventsToStoredMessages(
projected = true;
}

if (event.actions?.userQuestionRequest) {
// The matching function_call/function_response own the legacy rows;
// this request is live interaction state only.
projected = true;
}

if (event.actions?.permissionDecision) {
projected = projectPermissionDecision(event, state, messages) || projected;
}
Expand Down
Loading