Archived
Fix compaction status reset
This commit is contained in:
@@ -72,6 +72,16 @@ export class PiSessionService {
|
|||||||
(sessionId) => this.getActive(sessionId),
|
(sessionId) => this.getActive(sessionId),
|
||||||
(sessionId, text) => this.prompt(sessionId, text),
|
(sessionId, text) => this.prompt(sessionId, text),
|
||||||
events,
|
events,
|
||||||
|
{
|
||||||
|
onCompactionStart: (session) => {
|
||||||
|
this.publishActivity(session, "compacting", "active");
|
||||||
|
this.publishStatus(session);
|
||||||
|
},
|
||||||
|
onCompactionEnd: (session, result, detail) => {
|
||||||
|
this.publishActivity(session, result === "success" ? "compaction complete" : "compaction failed", result === "success" ? "idle" : "error", detail);
|
||||||
|
this.publishStatus(session);
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ export class SessionCommandService {
|
|||||||
private readonly getActive: GetActiveSession,
|
private readonly getActive: GetActiveSession,
|
||||||
private readonly prompt: (sessionId: string, text: string) => Promise<void>,
|
private readonly prompt: (sessionId: string, text: string) => Promise<void>,
|
||||||
private readonly events: SessionEventHub,
|
private readonly events: SessionEventHub,
|
||||||
|
private readonly lifecycle: {
|
||||||
|
onCompactionStart?: (session: AgentSession) => void;
|
||||||
|
onCompactionEnd?: (session: AgentSession, result: "success" | "error", detail?: string) => void;
|
||||||
|
} = {},
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async run(sessionId: string, text: string): Promise<ClientCommandResult> {
|
async run(sessionId: string, text: string): Promise<ClientCommandResult> {
|
||||||
@@ -60,6 +64,7 @@ export class SessionCommandService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private compact(session: AgentSession, instructions: string): ClientCommandResult {
|
private compact(session: AgentSession, instructions: string): ClientCommandResult {
|
||||||
|
this.lifecycle.onCompactionStart?.(session);
|
||||||
void session.compact(instructions === "" ? undefined : instructions)
|
void session.compact(instructions === "" ? undefined : instructions)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.events.publish(session.sessionId, {
|
this.events.publish(session.sessionId, {
|
||||||
@@ -67,11 +72,13 @@ export class SessionCommandService {
|
|||||||
level: "success",
|
level: "success",
|
||||||
message: formatCompactionResult(result),
|
message: formatCompactionResult(result),
|
||||||
});
|
});
|
||||||
|
this.lifecycle.onCompactionEnd?.(session, "success");
|
||||||
})
|
})
|
||||||
.catch((error: unknown) => {
|
.catch((error: unknown) => {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
this.events.publish(session.sessionId, { type: "command.output", level: "error", message: `Compaction failed: ${message}` });
|
this.events.publish(session.sessionId, { type: "command.output", level: "error", message: `Compaction failed: ${message}` });
|
||||||
this.events.publish(session.sessionId, { type: "session.error", message });
|
this.events.publish(session.sessionId, { type: "session.error", message });
|
||||||
|
this.lifecycle.onCompactionEnd?.(session, "error", message);
|
||||||
});
|
});
|
||||||
return { type: "done", message: "Compaction started…" };
|
return { type: "done", message: "Compaction started…" };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user