mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-29 06:13:46 +00:00
fix(codex): restore transcript messages from Codex 0.147
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { convertCodexEvent } from './codexEventConverter';
|
||||
import { convertCodexEvent, createCodexEventConverter } from './codexEventConverter';
|
||||
|
||||
describe('convertCodexEvent', () => {
|
||||
it('extracts session_meta id', () => {
|
||||
@@ -32,6 +32,72 @@ describe('convertCodexEvent', () => {
|
||||
expect(result?.userMessage).toBe('hello user');
|
||||
});
|
||||
|
||||
it('converts Codex 0.147 completed user-message items', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'event_msg',
|
||||
payload: {
|
||||
type: 'item_completed',
|
||||
turn_id: 'turn-147',
|
||||
item: {
|
||||
type: 'UserMessage',
|
||||
id: 'user-147',
|
||||
content: [{ type: 'Text', text: 'hello from 0.147' }]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
turnId: 'turn-147',
|
||||
userActivity: true,
|
||||
userMessage: 'hello from 0.147'
|
||||
});
|
||||
});
|
||||
|
||||
it('marks image-only completed user-message items as activity', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'event_msg',
|
||||
payload: {
|
||||
type: 'item_completed',
|
||||
turn_id: 'turn-image',
|
||||
item: {
|
||||
type: 'UserMessage',
|
||||
id: 'user-image',
|
||||
content: [{ type: 'Image', image_url: 'data:image/png;base64,abc' }]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
turnId: 'turn-image',
|
||||
userActivity: true
|
||||
});
|
||||
});
|
||||
|
||||
it('converts Codex 0.147 completed agent-message items', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'event_msg',
|
||||
payload: {
|
||||
type: 'item_completed',
|
||||
turn_id: 'turn-147',
|
||||
item: {
|
||||
type: 'AgentMessage',
|
||||
id: 'agent-147',
|
||||
phase: 'commentary',
|
||||
content: [{ type: 'Text', text: 'visible commentary' }]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
turnId: 'turn-147',
|
||||
messages: [{
|
||||
type: 'message',
|
||||
message: 'visible commentary',
|
||||
id: 'agent-147'
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('marks native token counts as inclusive of cached input', () => {
|
||||
const info = {
|
||||
total_token_usage: {
|
||||
@@ -122,14 +188,6 @@ describe('convertCodexEvent', () => {
|
||||
content: [{ type: 'input_image', image_url: 'data:image/png;base64,abc' }]
|
||||
}
|
||||
}],
|
||||
['assistant text', {
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
type: 'message',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'output_text', text: 'hello from response_item assistant' }]
|
||||
}
|
||||
}],
|
||||
['injected user context', {
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
@@ -142,6 +200,111 @@ describe('convertCodexEvent', () => {
|
||||
expect(convertCodexEvent(event)).toBeNull();
|
||||
});
|
||||
|
||||
it('converts assistant response items that have no semantic mirror', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
type: 'message',
|
||||
id: 'final-1',
|
||||
role: 'assistant',
|
||||
phase: 'final_answer',
|
||||
content: [{ type: 'output_text', text: 'complete final answer' }],
|
||||
internal_chat_message_metadata_passthrough: { turn_id: 'turn-1' }
|
||||
}
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
turnId: 'turn-1',
|
||||
messages: [{
|
||||
type: 'message',
|
||||
message: 'complete final answer',
|
||||
id: 'final-1'
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('removes the plan envelope from assistant response items', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
type: 'message',
|
||||
id: 'plan-preface',
|
||||
role: 'assistant',
|
||||
phase: 'final_answer',
|
||||
content: [{
|
||||
type: 'output_text',
|
||||
text: 'visible preface\n\n<proposed_plan>## Hidden duplicate plan</proposed_plan>'
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
expect(result?.messages?.[0]).toMatchObject({
|
||||
type: 'message',
|
||||
message: 'visible preface'
|
||||
});
|
||||
});
|
||||
|
||||
it('deduplicates legacy and 0.147 semantic messages against response items', () => {
|
||||
const convert = createCodexEventConverter();
|
||||
|
||||
convert({
|
||||
type: 'turn_context',
|
||||
payload: { turn_id: 'turn-1' }
|
||||
});
|
||||
expect(convert({
|
||||
type: 'event_msg',
|
||||
payload: { type: 'agent_message', phase: 'commentary', message: 'legacy commentary' }
|
||||
})?.messages?.[0]).toMatchObject({ message: 'legacy commentary' });
|
||||
expect(convert({
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
type: 'message',
|
||||
id: 'legacy-commentary',
|
||||
role: 'assistant',
|
||||
phase: 'commentary',
|
||||
content: [{ type: 'output_text', text: 'legacy commentary' }],
|
||||
internal_chat_message_metadata_passthrough: { turn_id: 'turn-1' }
|
||||
}
|
||||
})).toBeNull();
|
||||
|
||||
expect(convert({
|
||||
type: 'event_msg',
|
||||
payload: {
|
||||
type: 'item_completed',
|
||||
turn_id: 'turn-1',
|
||||
item: {
|
||||
type: 'AgentMessage',
|
||||
id: 'new-commentary',
|
||||
phase: 'commentary',
|
||||
content: [{ type: 'Text', text: 'new commentary' }]
|
||||
}
|
||||
}
|
||||
})?.messages?.[0]).toMatchObject({ message: 'new commentary' });
|
||||
expect(convert({
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
type: 'message',
|
||||
id: 'new-commentary',
|
||||
role: 'assistant',
|
||||
phase: 'commentary',
|
||||
content: [{ type: 'output_text', text: 'new commentary' }],
|
||||
internal_chat_message_metadata_passthrough: { turn_id: 'turn-1' }
|
||||
}
|
||||
})).toBeNull();
|
||||
|
||||
expect(convert({
|
||||
type: 'response_item',
|
||||
payload: {
|
||||
type: 'message',
|
||||
id: 'response-only-final',
|
||||
role: 'assistant',
|
||||
phase: 'final_answer',
|
||||
content: [{ type: 'output_text', text: 'response-only final' }],
|
||||
internal_chat_message_metadata_passthrough: { turn_id: 'turn-1' }
|
||||
}
|
||||
})?.messages?.[0]).toMatchObject({ message: 'response-only final' });
|
||||
});
|
||||
|
||||
it('converts reasoning events', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'event_msg',
|
||||
|
||||
Reference in New Issue
Block a user