feat(codex): import local Codex sessions into Hapi (#796)

* local: add Codex Desktop session sync controls

* feat(codex): import local Codex sessions into Hapi

---------

Co-authored-by: Codex Local <codex-local@example.invalid>
This commit is contained in:
DolphinZZZZZ
2026-06-04 17:53:12 +08:00
committed by GitHub
co-authored by Codex Local
parent 39fba5292c
commit f9ef3a4489
25 changed files with 3156 additions and 15 deletions
@@ -55,6 +55,30 @@ function asString(value: unknown): string | null {
return typeof value === 'string' && value.length > 0 ? value : null;
}
function extractCodexText(value: unknown): string {
if (typeof value === 'string') {
return value.trim();
}
if (Array.isArray(value)) {
return value
.map((item) => {
const record = asRecord(item);
if (record?.type === 'input_text' && typeof record.text === 'string') return record.text;
if (record?.type === 'output_text' && typeof record.text === 'string') return record.text;
if (record?.type === 'text' && typeof record.text === 'string') return record.text;
return null;
})
.filter((part): part is string => Boolean(part))
.join(' ')
.trim();
}
const record = asRecord(value);
if (record?.type === 'input_text' && typeof record.text === 'string') return record.text.trim();
if (record?.type === 'output_text' && typeof record.text === 'string') return record.text.trim();
if (record?.type === 'text' && typeof record.text === 'string') return record.text.trim();
return '';
}
function parseArguments(value: unknown): unknown {
if (typeof value !== 'string') {
return value;
@@ -194,6 +218,27 @@ export function convertCodexEvent(rawEvent: unknown): CodexConversionResult | nu
return null;
}
if (itemType === 'message') {
const role = asString(payloadRecord.role);
const text = extractCodexText(payloadRecord.content);
if (!text) {
return null;
}
if (role === 'user') {
return { userMessage: text };
}
if (role === 'assistant') {
return {
message: {
type: 'message',
message: text,
id: randomUUID()
}
};
}
return null;
}
if (itemType === 'function_call') {
const name = asString(payloadRecord.name);
const callId = extractCallId(payloadRecord);