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; } 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 }; "workspace.created": { workspace: PluginHookWorkspace }; "workspace.archived": { workspace: PluginHookWorkspace }; } export interface PluginBeforeRequests { "agent.create": { config: AgentSessionConfig; env?: Record }; "agent.session_open": PluginSessionOpenRequest; "workspace.create": Omit; } export interface PluginLifecycleRegistration { on( name: Name, handler: ( event: PluginLifecycleEvents[Name], context: PluginHookContext, ) => void | Promise, ): () => void; before( name: Name, handler: ( input: { request: PluginBeforeRequests[Name] }, context: PluginHookContext, ) => PluginBeforeRequests[Name] | void | Promise, ): () => void; }