import { AGENT_TEAM_PROCESS_RUN_PATH } from "../agent/durable-background.js"; import type { AgentEngine } from "../agent/engine/types.js"; import type { ActionEntry, AgentLoopFinalResponseGuard } from "../agent/production-agent.js"; import { type ActiveRun } from "../agent/run-manager.js"; import type { AgentChatEvent } from "../agent/types.js"; import type { RunEvent } from "../agent/types.js"; import type { BackgroundAgentRun, BackgroundAgentRunStatus, BackgroundAgentTranscriptEvent } from "../code-agents/background-run.js"; import type { BackgroundAgentController } from "../code-agents/index.js"; import { type AgentTeamRunPayload } from "./agent-teams-run-queue.js"; export { AGENT_TEAM_PROCESS_RUN_PATH }; declare function runWithDelegationDepth(depth: number, fn: () => T | Promise): T | Promise; declare function currentAmbientDelegationDepth(): number; export declare function getCurrentDelegationDepth(): number; export interface SubagentDepthDecision { allowed: boolean; parentDepth: number; childDepth: number; maxDepth: number; error?: string; } export declare function evaluateSubagentDepth(parentDepth: number, env?: Record): SubagentDepthDecision; export interface AgentTask { taskId: string; threadId: string; parentThreadId?: string; ownerEmail?: string | null; orgId?: string | null; name?: string; description: string; status: "running" | "completed" | "errored"; preview: string; summary: string; currentStep: string; createdAt: number; updatedAt?: number; startedAt?: number; completedAt?: number; runId?: string; error?: string; delegationDepth?: number; transcriptRunIds?: string[]; parentCompletionEnqueued?: boolean; hitContinuationLimit?: boolean; terminalEffectsVersion?: 1; terminalEffectsReconciled?: boolean; terminalProgressStatus?: TerminalProgressStatus; stopRequestedAt?: number; stopRequestedRunId?: string; stopRequestedReason?: string; } export interface AgentTeamOwnerScope { ownerEmail: string | null; orgId?: string | null; } export type AgentTeamBackgroundRun = Omit & { kind: "agent-team"; source: "hosted-agent-team"; sourceRecord: { type: "agent-team-task"; id: string; threadId: string; }; status: BackgroundAgentRunStatus; cwd?: string; goalId: "agent-team"; transcriptPath?: string; artifactRoot?: string; }; export type AgentTeamBackgroundTranscriptEvent = Omit & { kind: "user" | "system" | "note" | "artifact" | "status"; source: "hosted-agent-team"; sourceRecord: { type: "agent-team-run-event"; id: string; seq: number; }; }; export interface SendToAgentTeamBackgroundRunResult { ok: boolean; error?: string; messageId?: string; queuedCount?: number; } export interface ControlAgentTeamBackgroundRunResult { ok: boolean; error?: string; } export declare function createAgentTeamBackgroundAgentController(): BackgroundAgentController; export declare const agentTeamBackgroundAgentController: BackgroundAgentController; export interface ParentCompletionInjection { id: string; taskId: string; taskName?: string; status: "completed" | "errored"; hitContinuationLimit: boolean; summaryExcerpt: string; fullSummaryAvailable: boolean; timestamp: number; } export declare function drainParentCompletionInjections(parentThreadId: string): Promise; export declare function formatParentCompletionInjections(injections: ParentCompletionInjection[]): string; export interface QueuedTaskMessage { id: string; from: "orchestrator"; message: string; timestamp: number; } declare function formatQueuedTaskMessages(messages: QueuedTaskMessage[]): string; declare function drainQueuedTaskMessages(taskId: string): Promise; declare function createMessageAwareActions(taskId: string, actions: Record): Record; declare function createTaskMessageFinalGuard(taskId: string): AgentLoopFinalResponseGuard; export declare function reconcileAgentTeamRunsForOwner(owner: string, event?: any): Promise; export declare function reconcileStaleAgentTeamRuns(event?: any, limit?: number): Promise<{ examined: number; failed: number; }>; type TerminalProgressStatus = "succeeded" | "failed" | "cancelled"; declare function resolveTaskCompletion(run: Pick, accumulatedText: string, options?: { hitContinuationLimit?: boolean; }): { taskStatus: "completed" | "errored"; summary: string; progressStatus: TerminalProgressStatus; progressStep: string; error?: string; }; export declare function toAgentTaskBackgroundRun(task: AgentTask): AgentTeamBackgroundRun; export declare function toAgentTaskBackgroundTranscriptEvent(runId: string, event: RunEvent, options?: { seq?: number; sourceRunId?: string; }): AgentTeamBackgroundTranscriptEvent | null; export interface SpawnTaskOptions { description: string; instructions?: string; model?: string; ownerEmail: string; systemPrompt: string; actions: Record; engine?: AgentEngine; apiKey?: string; parentSend: (event: AgentChatEvent) => void; parentThreadId?: string; parentSourceAppId?: string | null; parentRunId?: string; name?: string; parentDelegationDepth?: number; } export declare class SubagentDelegationDepthError extends Error { readonly decision: SubagentDepthDecision; constructor(decision: SubagentDepthDecision); } export declare function spawnTask(opts: SpawnTaskOptions): Promise; export interface AgentTeamRunConfig { baseSystemPrompt: string; actions: Record; engine: AgentEngine; model: string; initialToolNames?: string[]; } export interface ProcessAgentTeamRunOptions { taskId: string; mode?: "start" | "continue"; event?: any; noProgressCount?: number; /** Builds the sub-agent run config from the queue payload + resolved owner. * The plugin supplies this because the action registry / base prompt / * engine are per-deployment plugin-scope closures, not serializable. */ resolveConfig: (ctx: { payload: AgentTeamRunPayload; ownerEmail: string; orgId: string | null; }) => Promise; } export declare function processAgentTeamRun(opts: ProcessAgentTeamRunOptions): Promise<{ ok: boolean; skipped?: string; }>; export declare function getTask(taskId: string, scope?: AgentTeamOwnerScope): Promise; export declare function getTaskByThread(threadId: string, scope?: AgentTeamOwnerScope): Promise; export declare function listTasks(scope?: AgentTeamOwnerScope): Promise; export declare function listAgentTeamBackgroundRuns(scope?: AgentTeamOwnerScope): Promise; export declare function getAgentTeamBackgroundRun(runId: string, scope?: AgentTeamOwnerScope): Promise; export declare function listAgentTeamBackgroundTranscriptEvents(runId: string, scope?: AgentTeamOwnerScope): Promise; export declare function subscribeToAgentTeamBackgroundRun(runId: string, fromSeq?: number): ReadableStream | null; export declare function sendToTask(taskId: string, message: string, scope?: AgentTeamOwnerScope): Promise<{ ok: boolean; error?: string; messageId?: string; queuedCount?: number; }>; export declare function sendToAgentTeamBackgroundRun(runId: string, message: string, scope?: AgentTeamOwnerScope): Promise; export declare function stopAgentTeamBackgroundRun(runId: string, reason?: string, scope?: AgentTeamOwnerScope): Promise; export declare function markTaskErrored(taskId: string, error: string): Promise; export declare const _agentTeamsQueueForTests: { createMessageAwareActions: typeof createMessageAwareActions; createTaskMessageFinalGuard: typeof createTaskMessageFinalGuard; drainQueuedTaskMessages: typeof drainQueuedTaskMessages; formatQueuedTaskMessages: typeof formatQueuedTaskMessages; resolveTaskCompletion: typeof resolveTaskCompletion; evaluateSubagentDepth: typeof evaluateSubagentDepth; runWithDelegationDepth: typeof runWithDelegationDepth; currentAmbientDelegationDepth: typeof currentAmbientDelegationDepth; };