mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 17:00:59 +00:00
Merge pull request #568 from tmustier/gemini-raw-stream
fix: restore ESC interrupt after auto-retry and correct retry abort messaging
This commit is contained in:
commit
7a2c19cdf0
4 changed files with 199 additions and 146 deletions
|
|
@ -435,6 +435,11 @@ export class AgentSession {
|
|||
return this.agent.state.isStreaming;
|
||||
}
|
||||
|
||||
/** Current retry attempt (0 if not retrying) */
|
||||
get retryAttempt(): number {
|
||||
return this._retryAttempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of currently active tools.
|
||||
* Returns the names of tools currently set on the agent.
|
||||
|
|
@ -1567,7 +1572,7 @@ export class AgentSession {
|
|||
*/
|
||||
abortRetry(): void {
|
||||
this._retryAbortController?.abort();
|
||||
this._retryAttempt = 0;
|
||||
// Note: _retryAttempt is reset in the catch block of _autoRetry
|
||||
this._resolveRetry();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,12 +31,11 @@ export class AssistantMessageComponent extends Container {
|
|||
// Clear content container
|
||||
this.contentContainer.clear();
|
||||
|
||||
if (
|
||||
message.content.length > 0 &&
|
||||
message.content.some(
|
||||
(c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()),
|
||||
)
|
||||
) {
|
||||
const hasVisibleContent = message.content.some(
|
||||
(c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()),
|
||||
);
|
||||
|
||||
if (hasVisibleContent) {
|
||||
this.contentContainer.addChild(new Spacer(1));
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +74,12 @@ export class AssistantMessageComponent extends Container {
|
|||
const hasToolCalls = message.content.some((c) => c.type === "toolCall");
|
||||
if (!hasToolCalls) {
|
||||
if (message.stopReason === "aborted") {
|
||||
this.contentContainer.addChild(new Text(theme.fg("error", "\nAborted"), 1, 0));
|
||||
const abortMessage =
|
||||
message.errorMessage && message.errorMessage !== "Request was aborted"
|
||||
? message.errorMessage
|
||||
: "Operation aborted";
|
||||
const prefix = hasVisibleContent ? "\n" : "";
|
||||
this.contentContainer.addChild(new Text(theme.fg("error", `${prefix}${abortMessage}`), 1, 0));
|
||||
} else if (message.stopReason === "error") {
|
||||
const errorMsg = message.errorMessage || "Unknown error";
|
||||
this.contentContainer.addChild(new Spacer(1));
|
||||
|
|
|
|||
|
|
@ -1481,6 +1481,16 @@ export class InteractiveMode {
|
|||
|
||||
switch (event.type) {
|
||||
case "agent_start":
|
||||
// Restore main escape handler if retry handler is still active
|
||||
// (retry success event fires later, but we need main handler now)
|
||||
if (this.retryEscapeHandler) {
|
||||
this.defaultEditor.onEscape = this.retryEscapeHandler;
|
||||
this.retryEscapeHandler = undefined;
|
||||
}
|
||||
if (this.retryLoader) {
|
||||
this.retryLoader.stop();
|
||||
this.retryLoader = undefined;
|
||||
}
|
||||
if (this.loadingAnimation) {
|
||||
this.loadingAnimation.stop();
|
||||
}
|
||||
|
|
@ -1549,13 +1559,21 @@ export class InteractiveMode {
|
|||
if (event.message.role === "user") break;
|
||||
if (this.streamingComponent && event.message.role === "assistant") {
|
||||
this.streamingMessage = event.message;
|
||||
let errorMessage: string | undefined;
|
||||
if (this.streamingMessage.stopReason === "aborted") {
|
||||
const retryAttempt = this.session.retryAttempt;
|
||||
errorMessage =
|
||||
retryAttempt > 0
|
||||
? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? "s" : ""}`
|
||||
: "Operation aborted";
|
||||
this.streamingMessage.errorMessage = errorMessage;
|
||||
}
|
||||
this.streamingComponent.updateContent(this.streamingMessage);
|
||||
|
||||
if (this.streamingMessage.stopReason === "aborted" || this.streamingMessage.stopReason === "error") {
|
||||
const errorMessage =
|
||||
this.streamingMessage.stopReason === "aborted"
|
||||
? "Operation aborted"
|
||||
: this.streamingMessage.errorMessage || "Error";
|
||||
if (!errorMessage) {
|
||||
errorMessage = this.streamingMessage.errorMessage || "Error";
|
||||
}
|
||||
for (const [, component] of this.pendingTools.entries()) {
|
||||
component.updateResult({
|
||||
content: [{ type: "text", text: errorMessage }],
|
||||
|
|
@ -1862,8 +1880,16 @@ export class InteractiveMode {
|
|||
this.chatContainer.addChild(component);
|
||||
|
||||
if (message.stopReason === "aborted" || message.stopReason === "error") {
|
||||
const errorMessage =
|
||||
message.stopReason === "aborted" ? "Operation aborted" : message.errorMessage || "Error";
|
||||
let errorMessage: string;
|
||||
if (message.stopReason === "aborted") {
|
||||
const retryAttempt = this.session.retryAttempt;
|
||||
errorMessage =
|
||||
retryAttempt > 0
|
||||
? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? "s" : ""}`
|
||||
: "Operation aborted";
|
||||
} else {
|
||||
errorMessage = message.errorMessage || "Error";
|
||||
}
|
||||
component.updateResult({ content: [{ type: "text", text: errorMessage }], isError: true });
|
||||
} else {
|
||||
this.pendingTools.set(content.id, component);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue