mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:24:31 +00:00
fix(gateway+acp): thread stopReason through final event to ACP bridge (#24867)
Complete the stop reason propagation chain so ACP clients can distinguish end_turn from max_tokens: - server-chat.ts: emitChatFinal accepts optional stopReason param, includes it in the final payload, reads it from lifecycle event data - translator.ts: read stopReason from the final payload instead of hardcoding end_turn Chain: LLM API → run.ts (meta.stopReason) → agent.ts (lifecycle event) → server-chat.ts (final payload) → ACP translator (PromptResponse)
This commit is contained in:
@@ -423,7 +423,9 @@ export class AcpGatewayAgent implements Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state === "final") {
|
if (state === "final") {
|
||||||
this.finishPrompt(pending.sessionId, pending, "end_turn");
|
const rawStopReason = payload.stopReason as string | undefined;
|
||||||
|
const stopReason: StopReason = rawStopReason === "max_tokens" ? "max_tokens" : "end_turn";
|
||||||
|
this.finishPrompt(pending.sessionId, pending, stopReason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state === "aborted") {
|
if (state === "aborted") {
|
||||||
|
|||||||
@@ -346,6 +346,7 @@ export function createAgentEventHandler({
|
|||||||
seq: number,
|
seq: number,
|
||||||
jobState: "done" | "error",
|
jobState: "done" | "error",
|
||||||
error?: unknown,
|
error?: unknown,
|
||||||
|
stopReason?: string,
|
||||||
) => {
|
) => {
|
||||||
const bufferedText = stripInlineDirectiveTagsForDisplay(
|
const bufferedText = stripInlineDirectiveTagsForDisplay(
|
||||||
chatRunState.buffers.get(clientRunId) ?? "",
|
chatRunState.buffers.get(clientRunId) ?? "",
|
||||||
@@ -399,6 +400,7 @@ export function createAgentEventHandler({
|
|||||||
sessionKey,
|
sessionKey,
|
||||||
seq,
|
seq,
|
||||||
state: "final" as const,
|
state: "final" as const,
|
||||||
|
...(stopReason && { stopReason }),
|
||||||
message:
|
message:
|
||||||
text && !shouldSuppressSilent
|
text && !shouldSuppressSilent
|
||||||
? {
|
? {
|
||||||
@@ -512,6 +514,8 @@ export function createAgentEventHandler({
|
|||||||
if (!isAborted && evt.stream === "assistant" && typeof evt.data?.text === "string") {
|
if (!isAborted && evt.stream === "assistant" && typeof evt.data?.text === "string") {
|
||||||
emitChatDelta(sessionKey, clientRunId, evt.runId, evt.seq, evt.data.text);
|
emitChatDelta(sessionKey, clientRunId, evt.runId, evt.seq, evt.data.text);
|
||||||
} else if (!isAborted && (lifecyclePhase === "end" || lifecyclePhase === "error")) {
|
} else if (!isAborted && (lifecyclePhase === "end" || lifecyclePhase === "error")) {
|
||||||
|
const evtStopReason =
|
||||||
|
typeof evt.data?.stopReason === "string" ? evt.data.stopReason : undefined;
|
||||||
if (chatLink) {
|
if (chatLink) {
|
||||||
const finished = chatRunState.registry.shift(evt.runId);
|
const finished = chatRunState.registry.shift(evt.runId);
|
||||||
if (!finished) {
|
if (!finished) {
|
||||||
@@ -525,6 +529,7 @@ export function createAgentEventHandler({
|
|||||||
evt.seq,
|
evt.seq,
|
||||||
lifecyclePhase === "error" ? "error" : "done",
|
lifecyclePhase === "error" ? "error" : "done",
|
||||||
evt.data?.error,
|
evt.data?.error,
|
||||||
|
evtStopReason,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
emitChatFinal(
|
emitChatFinal(
|
||||||
@@ -534,6 +539,7 @@ export function createAgentEventHandler({
|
|||||||
evt.seq,
|
evt.seq,
|
||||||
lifecyclePhase === "error" ? "error" : "done",
|
lifecyclePhase === "error" ? "error" : "done",
|
||||||
evt.data?.error,
|
evt.data?.error,
|
||||||
|
evtStopReason,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (isAborted && (lifecyclePhase === "end" || lifecyclePhase === "error")) {
|
} else if (isAborted && (lifecyclePhase === "end" || lifecyclePhase === "error")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user