feat: mirror boss messages via app server
This commit is contained in:
@@ -86,6 +86,17 @@ function isThreadForkTask(task) {
|
||||
return task?.intentCategory === "thread_fork" || task?.taskType === "thread_fork";
|
||||
}
|
||||
|
||||
function shouldMirrorBossUserMessageToCodexThread(task) {
|
||||
return (
|
||||
task?.mirrorBossUserMessageToCodexDesktop === true ||
|
||||
task?.syncUserMessageToCodexThread === true
|
||||
);
|
||||
}
|
||||
|
||||
function resolveBossUserMessageText(task) {
|
||||
return trimToDefined(task?.sourceMessageBody) || trimToDefined(task?.requestText);
|
||||
}
|
||||
|
||||
function resolveThreadRenameName(task) {
|
||||
return trimToDefined(task?.threadRenameName || task?.threadName || task?.name);
|
||||
}
|
||||
@@ -2896,6 +2907,50 @@ async function maybeInjectInterThreadContext({ request, task, targetThreadId })
|
||||
};
|
||||
}
|
||||
|
||||
function buildBossUserMessageInjectionItem({ task, text }) {
|
||||
return {
|
||||
type: "message",
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "input_text",
|
||||
text,
|
||||
},
|
||||
],
|
||||
metadata: {
|
||||
boss_source: "boss_app",
|
||||
boss_message_kind: "user_message",
|
||||
...(trimToDefined(task?.sourceMessageSentAt)
|
||||
? { boss_source_sent_at: trimToDefined(task.sourceMessageSentAt) }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function maybeInjectBossUserMessage({ request, task, targetThreadId, targetTurnId, hasExistingThreadRef }) {
|
||||
if (
|
||||
!targetThreadId ||
|
||||
targetTurnId ||
|
||||
!hasExistingThreadRef ||
|
||||
!shouldMirrorBossUserMessageToCodexThread(task)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
const text = resolveBossUserMessageText(task);
|
||||
if (!text) {
|
||||
return undefined;
|
||||
}
|
||||
await request("thread/inject_items", {
|
||||
threadId: targetThreadId,
|
||||
items: [buildBossUserMessageInjectionItem({ task, text })],
|
||||
});
|
||||
return {
|
||||
threadId: targetThreadId,
|
||||
injectedItemCount: 1,
|
||||
source: "boss_user_message",
|
||||
};
|
||||
}
|
||||
|
||||
export async function executeCodexAppServerTask(runnerConfig, task) {
|
||||
if (!shouldUseCodexAppServerTaskRunner(runnerConfig, task)) {
|
||||
return createFailure("CODEX_APP_SERVER_DISABLED", { canFallbackToCli: true });
|
||||
@@ -3385,6 +3440,13 @@ export async function executeCodexAppServerTask(runnerConfig, task) {
|
||||
task,
|
||||
targetThreadId: threadId,
|
||||
});
|
||||
const threadHistorySync = await maybeInjectBossUserMessage({
|
||||
request,
|
||||
task,
|
||||
targetThreadId: threadId,
|
||||
targetTurnId: targetTurnRef,
|
||||
hasExistingThreadRef: Boolean(targetThreadRef),
|
||||
});
|
||||
|
||||
const turnControl = targetTurnRef ? "steer" : "start";
|
||||
const turnResult = targetTurnRef
|
||||
@@ -3420,6 +3482,7 @@ export async function executeCodexAppServerTask(runnerConfig, task) {
|
||||
transport: runnerConfig.transport,
|
||||
executionProgress: progressCollector.snapshot(),
|
||||
interThreadBroker,
|
||||
threadHistorySync,
|
||||
canFallbackToCli: false,
|
||||
};
|
||||
}
|
||||
@@ -3433,6 +3496,7 @@ export async function executeCodexAppServerTask(runnerConfig, task) {
|
||||
transport: runnerConfig.transport,
|
||||
executionProgress: progressCollector.snapshot(),
|
||||
interThreadBroker,
|
||||
threadHistorySync,
|
||||
canFallbackToCli: false,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user