Skip to content

Commit bfd3791

Browse files
committed
unify viewer with codex
1 parent 4acd59b commit bfd3791

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

viewer.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ function contentText(contents) {
6868
for (const c of contents ?? []) {
6969
const type = c && typeof c === 'object' ? deltaField(c, 'type') : undefined;
7070
const text = c && typeof c === 'object' ? deltaField(c, 'text') : c;
71-
if (type === 'input_text' || type === 'output_text' || type === 'text')
71+
if (type === 'input_text') {
72+
const raw = String(text ?? '');
73+
const divider = '## My request for Codex:';
74+
const i = raw.indexOf(divider);
75+
r.push(i < 0 ? raw : raw.slice(i + divider.length).replace(/^\s+/, ''));
76+
} else if (type === 'output_text' || type === 'text') {
7277
r.push(String(text ?? ''));
73-
else r.push(`[${String(type ?? '?')}]`);
78+
} else r.push(`[${String(type ?? '?')}]`);
7479
}
7580
return r.join('\n');
7681
}
@@ -196,6 +201,11 @@ function renderPayload(elements) {
196201
function render(data, label) {
197202
const id = data?._id !== undefined ? ` #${esc(String(data._id))}` : '';
198203
const purpose = data?._purpose ? ` ${esc(String(data._purpose))}` : '';
204+
const isPrimary =
205+
data?._purpose === undefined ||
206+
data?._purpose === '' ||
207+
data?._purpose === '[turn]' ||
208+
data?._purpose === '[/responses]';
199209
if (data?.[TITLE] !== undefined) {
200210
return data;
201211
} else if (data?._kind === 'request') {
@@ -204,9 +214,9 @@ function render(data, label) {
204214
delete raw._kind;
205215
const title = `REQUEST${id}${purpose}`;
206216
return {
207-
[TITLE]: `[${esc(ts(data))}] ${data._purpose === '[meta]' ? title : `<b>${title}</b>`} `,
217+
[TITLE]: `[${esc(ts(data))}] ${isPrimary ? `<b>${title}</b>` : title} `,
208218
body: [...rendered, {[TITLE]: 'raw', body: raw}],
209-
open: data._purpose !== '[meta]',
219+
open: isPrimary,
210220
};
211221
} else if (data?._kind === 'response') {
212222
const payload = renderPayload(
@@ -216,9 +226,9 @@ function render(data, label) {
216226
delete raw._kind;
217227
const title = `RESPONSE${id}${purpose}`;
218228
return {
219-
[TITLE]: `[${esc(ts(data))}] ${data._purpose === '[meta]' ? title : `<b>${title}</b>`} `,
229+
[TITLE]: `[${esc(ts(data))}] ${isPrimary ? `<b>${title}</b>` : title} `,
220230
body: [...payload, {[TITLE]: 'raw', body: raw}],
221-
open: data._purpose !== '[meta]',
231+
open: isPrimary,
222232
};
223233
} else if (data?._kind === 'error') {
224234
const raw = {...data};

0 commit comments

Comments
 (0)