Merge remote-tracking branch 'origin/main' into exec-approvals
This commit is contained in:
commit
b85138d32d
9 changed files with 657 additions and 27 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { v7 as uuidv7 } from "uuid";
|
||||
import type { AgentEvent } from "@mariozechner/pi-agent-core";
|
||||
import type { AgentEvent, AgentMessage } from "@mariozechner/pi-agent-core";
|
||||
import { Agent } from "./runner.js";
|
||||
import { Channel } from "./channel.js";
|
||||
import type { AgentOptions, Message } from "./types.js";
|
||||
|
|
@ -58,6 +58,22 @@ export class AsyncAgent {
|
|||
return this.channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to agent events directly (supports multiple subscribers).
|
||||
* Unlike read(), this allows multiple consumers to receive the same events.
|
||||
*/
|
||||
subscribe(callback: (event: AgentEvent) => void): () => void {
|
||||
console.log(`[AsyncAgent] Adding subscriber for agent: ${this.sessionId}`);
|
||||
const unsubscribe = this.agent.subscribe((event) => {
|
||||
console.log(`[AsyncAgent] Event received: ${event.type}`);
|
||||
callback(event);
|
||||
});
|
||||
return () => {
|
||||
console.log(`[AsyncAgent] Removing subscriber for agent: ${this.sessionId}`);
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
|
||||
/** Returns a promise that resolves when the current message queue is drained */
|
||||
waitForIdle(): Promise<void> {
|
||||
return this.queue;
|
||||
|
|
@ -198,4 +214,11 @@ export class AsyncAgent {
|
|||
reloadSystemPrompt(): void {
|
||||
this.agent.reloadSystemPrompt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all messages from the current session.
|
||||
*/
|
||||
getMessages(): AgentMessage[] {
|
||||
return this.agent.getMessages();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -482,6 +482,11 @@ export class Agent {
|
|||
return this.agent.state.tools?.map(t => t.name) ?? [];
|
||||
}
|
||||
|
||||
/** Get all messages from the current session */
|
||||
getMessages(): AgentMessage[] {
|
||||
return this.agent.state.messages.slice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all skills with their eligibility status.
|
||||
* Returns empty array if skills are disabled.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue