File size: 1,971 Bytes
68d7816 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
import type { Event } from '#/_base/event';
import type { TokenUsage } from '#human/llm/usage';
import type { AgentContext } from '#/agent/agentContext/agentContext';
import type { Turn } from '#/agent/loop/loop';
import type { Hooks } from '#/hooks';
import type {
SpawnSubagentOptions,
SpawnedSubagent,
SubagentSpawnPlan,
SubagentSpawnPlanInput,
} from './spawn';
export type AgentRunRequest =
| { readonly kind: 'prompt'; readonly prompt: string }
| { readonly kind: 'retry'; readonly trigger?: string };
export interface RunAgentOptions {
readonly signal: AbortSignal;
readonly onReady?: () => void;
}
export interface AgentRunCompletion {
readonly summary: string;
readonly usage?: TokenUsage;
readonly stopReason?: string;
}
export interface AgentRunHandle {
readonly agentId: string;
readonly turn: Turn;
readonly completion: Promise<AgentRunCompletion>;
}
export interface AgentTaskStartHookContext {
readonly agentName: string;
readonly prompt: string;
readonly signal: AbortSignal;
}
export interface AgentTaskStopHookContext {
readonly agentName: string;
readonly response: string;
}
export type AgentTaskHooks = {
readonly onWillStartAgentTask: AgentTaskStartHookContext;
};
export interface ISessionSubagentService {
readonly _serviceBrand: undefined;
readonly hooks: Hooks<AgentTaskHooks>;
readonly onDidStopAgentTask: Event<AgentTaskStopHookContext>;
run(agent: AgentContext, request: AgentRunRequest, opts: RunAgentOptions): Promise<AgentRunHandle>;
planSpawn(input: SubagentSpawnPlanInput): Promise<SubagentSpawnPlan>;
spawn(opts: SpawnSubagentOptions): Promise<SpawnedSubagent>;
notifyAgentTaskStopped(context: AgentTaskStopHookContext): void;
}
export const ISessionSubagentService: ServiceIdentifier<ISessionSubagentService> =
createDecorator<ISessionSubagentService>('sessionSubagentService');
|