mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:51:24 +00:00
Auto-reply: delay onAgentRunStart until real activity
This commit is contained in:
@@ -88,7 +88,14 @@ export async function runAgentTurnWithFallback(params: {
|
||||
const directlySentBlockKeys = new Set<string>();
|
||||
|
||||
const runId = params.opts?.runId ?? crypto.randomUUID();
|
||||
params.opts?.onAgentRunStart?.(runId);
|
||||
let didNotifyAgentRunStart = false;
|
||||
const notifyAgentRunStart = () => {
|
||||
if (didNotifyAgentRunStart) {
|
||||
return;
|
||||
}
|
||||
didNotifyAgentRunStart = true;
|
||||
params.opts?.onAgentRunStart?.(runId);
|
||||
};
|
||||
if (params.sessionKey) {
|
||||
registerAgentRunContext(runId, {
|
||||
sessionKey: params.sessionKey,
|
||||
@@ -160,6 +167,7 @@ export async function runAgentTurnWithFallback(params: {
|
||||
|
||||
if (isCliProvider(provider, params.followupRun.run.config)) {
|
||||
const startedAt = Date.now();
|
||||
notifyAgentRunStart();
|
||||
emitAgentEvent({
|
||||
runId,
|
||||
stream: "lifecycle",
|
||||
@@ -310,6 +318,12 @@ export async function runAgentTurnWithFallback(params: {
|
||||
: undefined,
|
||||
onReasoningEnd: params.opts?.onReasoningEnd,
|
||||
onAgentEvent: async (evt) => {
|
||||
// Signal run start only after the embedded agent emits real activity.
|
||||
const hasLifecyclePhase =
|
||||
evt.stream === "lifecycle" && typeof evt.data.phase === "string";
|
||||
if (evt.stream !== "lifecycle" || hasLifecyclePhase) {
|
||||
notifyAgentRunStart();
|
||||
}
|
||||
// Trigger typing when tools start executing.
|
||||
// Must await to ensure typing indicator starts before tool summaries are emitted.
|
||||
if (evt.stream === "tool") {
|
||||
|
||||
Reference in New Issue
Block a user