mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-25 10:42:45 +00:00
* feat(plugins): expose agent closed lifecycle event Emit the event when a live agent reaches its closed state so plugins can release agent-scoped resources. Keep archive and close notifications distinct. Co-authored-by: ilteoood <6383527+ilteoood@users.noreply.github.com> * fix(plugins): finish close hooks during daemon shutdown Wait briefly for pending lifecycle events before stopping plugins so agent close hooks can release their resources during shutdown. Co-authored-by: ilteoood <6383527+ilteoood@users.noreply.github.com> --------- Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: ilteoood <6383527+ilteoood@users.noreply.github.com>
90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import type {
|
|
AgentPermissionRequest,
|
|
AgentPermissionResponse,
|
|
AgentTimelineItem,
|
|
AgentSessionConfig,
|
|
} from "@getpaseo/protocol/agent-types";
|
|
import type { PaseoApi } from "@getpaseo/client";
|
|
import type { WorkspaceCreateRequest } from "@getpaseo/protocol/messages";
|
|
|
|
export interface PluginHookContext {
|
|
paseo: PaseoApi;
|
|
signal: AbortSignal;
|
|
}
|
|
|
|
export interface PluginHookWorkspace {
|
|
id: string;
|
|
projectId: string;
|
|
cwd: string;
|
|
name: string | null;
|
|
archivedAt: string | null;
|
|
}
|
|
|
|
export interface PluginHookAgent {
|
|
id: string;
|
|
workspaceId: string | null;
|
|
parentAgentId: string | null;
|
|
provider: string;
|
|
cwd: string;
|
|
title: string | null;
|
|
}
|
|
|
|
export interface PluginSessionOpenRequest {
|
|
agentId: string;
|
|
workspaceId: string | null;
|
|
provider: string;
|
|
cwd: string;
|
|
reason: "create" | "resume" | "refresh" | "import";
|
|
purpose: "interactive" | "history";
|
|
env: Record<string, string>;
|
|
}
|
|
|
|
export type PluginTurnOutcome =
|
|
| { kind: "completed" }
|
|
| { kind: "failed"; error: { message: string; code?: string } }
|
|
| { kind: "canceled"; reason: string };
|
|
|
|
export interface PluginLifecycleEvents {
|
|
"agent.turn_started": { agent: PluginHookAgent; turnId: string | null };
|
|
"agent.turn_ended": {
|
|
agent: PluginHookAgent;
|
|
turnId: string | null;
|
|
outcome: PluginTurnOutcome;
|
|
timeline: readonly AgentTimelineItem[];
|
|
};
|
|
"agent.permission_requested": { agent: PluginHookAgent; request: AgentPermissionRequest };
|
|
"agent.permission_resolved": {
|
|
agent: PluginHookAgent;
|
|
requestId: string;
|
|
resolution: AgentPermissionResponse;
|
|
};
|
|
"agent.archived": { agent: PluginHookAgent; archivedAt: string };
|
|
"agent.created": { agent: PluginHookAgent };
|
|
"agent.closed": { agent: PluginHookAgent };
|
|
"workspace.created": { workspace: PluginHookWorkspace };
|
|
"workspace.archived": { workspace: PluginHookWorkspace };
|
|
}
|
|
|
|
export interface PluginBeforeRequests {
|
|
"agent.create": { config: AgentSessionConfig; env?: Record<string, string> };
|
|
"agent.session_open": PluginSessionOpenRequest;
|
|
"workspace.create": Omit<WorkspaceCreateRequest, "type" | "requestId">;
|
|
}
|
|
|
|
export interface PluginLifecycleRegistration {
|
|
on<Name extends keyof PluginLifecycleEvents>(
|
|
name: Name,
|
|
handler: (
|
|
event: PluginLifecycleEvents[Name],
|
|
context: PluginHookContext,
|
|
) => void | Promise<void>,
|
|
): () => void;
|
|
before<Name extends keyof PluginBeforeRequests>(
|
|
name: Name,
|
|
handler: (
|
|
input: { request: PluginBeforeRequests[Name] },
|
|
context: PluginHookContext,
|
|
) => PluginBeforeRequests[Name] | void | Promise<PluginBeforeRequests[Name] | void>,
|
|
): () => void;
|
|
}
|