fix: show codexapp steer insertion status
This commit is contained in:
39
server.js
39
server.js
@@ -4583,6 +4583,12 @@ function normalizeCodexAppUserInputAnswers(rawAnswers = {}) {
|
||||
return { answers };
|
||||
}
|
||||
|
||||
function previewInlineText(text, maxLength = 36) {
|
||||
const normalized = String(text || '').replace(/\s+/g, ' ').trim();
|
||||
if (!normalized) return '空内容';
|
||||
return normalized.length > maxLength ? `${normalized.slice(0, maxLength - 1)}...` : normalized;
|
||||
}
|
||||
|
||||
function requestCodexAppUserInput(routed, params = {}) {
|
||||
if (!routed?.entry?.ws) {
|
||||
return Promise.resolve({ answers: {} });
|
||||
@@ -5046,8 +5052,23 @@ function handleCodexAppSteerMessage(ws, msg, options = {}) {
|
||||
const sessionId = sanitizeId(msg?.sessionId || '');
|
||||
const entry = activeCodexAppTurns.get(sessionId);
|
||||
if (!entry) return null;
|
||||
const clientMessageId = String(msg?.clientMessageId || '').trim();
|
||||
|
||||
const sendSteerStatus = (status, message) => {
|
||||
const targetWs = entry.ws || ws;
|
||||
if (!targetWs) return;
|
||||
const payload = {
|
||||
type: 'codex_app_steer_status',
|
||||
sessionId,
|
||||
status,
|
||||
message,
|
||||
};
|
||||
if (clientMessageId) payload.clientMessageId = clientMessageId;
|
||||
wsSend(targetWs, payload);
|
||||
};
|
||||
|
||||
const fail = (code, message) => {
|
||||
sendSteerStatus('failed', '插入失败');
|
||||
wsSend(ws, { type: 'error', code, message });
|
||||
return { ok: false, code, message };
|
||||
};
|
||||
@@ -5099,18 +5120,32 @@ function handleCodexAppSteerMessage(ws, msg, options = {}) {
|
||||
wsSend(ws, { type: 'session_message', sessionId, message: persistedUserMessage });
|
||||
}
|
||||
|
||||
sendSteerStatus('pending', '引导中...');
|
||||
const input = codexAppInputFromMessage(runtimeTextValue, []);
|
||||
const expectedTurnId = entry.turnId;
|
||||
codexAppClient.request('turn/steer', {
|
||||
threadId: entry.threadId,
|
||||
expectedTurnId,
|
||||
input,
|
||||
clientUserMessageId: crypto.randomUUID(),
|
||||
}, 60000).catch((err) => {
|
||||
clientUserMessageId: clientMessageId || crypto.randomUUID(),
|
||||
}, 60000).then(() => {
|
||||
sendSteerStatus('inserted', '已插入');
|
||||
wsSend(entry.ws || ws, {
|
||||
type: 'system_message',
|
||||
sessionId,
|
||||
tone: 'info',
|
||||
transient: true,
|
||||
autoDismissMs: 5000,
|
||||
message: `已引导对话: ${previewInlineText(textValue)}`,
|
||||
});
|
||||
}).catch((err) => {
|
||||
sendSteerStatus('failed', '插入失败');
|
||||
wsSend(entry.ws || ws, {
|
||||
type: 'error',
|
||||
sessionId,
|
||||
code: 'codexapp_steer_failed',
|
||||
transient: true,
|
||||
autoDismissMs: 7000,
|
||||
message: formatRuntimeError('codex', err?.message || err, { exitCode: null, signal: null }),
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user