/** * Human-in-the-loop primitives implementation */ import type { Role, Team, Goal, KPI, OKR } from 'org.ai'; import type { Human as HumanType, HumanOptions, ApprovalResponse, ReviewResponse, Notification, ReviewQueue, ApprovalWorkflow, Priority, HumanRequest } from './types.js'; import { HumanRetryPolicy, HumanCircuitBreaker, SLATracker } from './timeout-retry.js'; /** * Human-in-the-loop manager * * Provides primitives for integrating human oversight and intervention * in AI workflows. * * @example * ```ts * const human = Human({ * defaultTimeout: 3600000, // 1 hour * autoEscalate: true, * }) * * // Request approval * const approval = await human.approve({ * title: 'Deploy to production', * description: 'Approve deployment of v2.0.0', * subject: 'Production Deployment', * assignee: 'tech-lead@example.com', * priority: 'high', * }) * * if (approval.approved) { * await deploy() * } * ``` */ export declare class HumanManager { private store; private options; private roles; private teams; private humans; private escalationPolicies; private workflows; private retryPolicy?; private circuitBreaker?; private slaTracker?; constructor(options?: HumanOptions); /** * Initialize timeout/retry components based on options */ private initializeRetryComponents; /** * Get the retry policy instance */ getRetryPolicy(): HumanRetryPolicy | undefined; /** * Get the circuit breaker instance */ getCircuitBreaker(): HumanCircuitBreaker | undefined; /** * Get the SLA tracker instance */ getSLATracker(): SLATracker | undefined; /** * Define a role */ defineRole(role: Role): Role; /** * Get a role by ID */ getRole(id: string): Role | undefined; /** * Define a team */ defineTeam(team: Team): Team; /** * Get a team by ID */ getTeam(id: string): Team | undefined; /** * Register a human worker */ registerHuman(human: HumanType): HumanType; /** * Get a human by ID */ getHuman(id: string): HumanType | undefined; /** * Request approval from a human * * @example * ```ts * const result = await human.approve({ * title: 'Approve expense', * description: 'Employee expense claim for $150', * subject: 'Expense Claim #1234', * input: { amount: 150, category: 'Travel' }, * assignee: 'manager@example.com', * priority: 'normal', * }) * ``` */ approve(params: { title: string; description: string; subject: string; input: TData; assignee?: string | string[]; role?: string; team?: string; priority?: Priority; timeout?: number; escalatesTo?: string | string[]; requiresApproval?: boolean; approvers?: string[]; metadata?: Record; }): Promise; /** * Ask a question to a human * * @example * ```ts * const answer = await human.ask({ * title: 'Product naming', * question: 'What should we name the new feature?', * context: { feature: 'AI Assistant' }, * assignee: 'product-manager@example.com', * }) * ``` */ ask(params: { title: string; question: string; context?: unknown; assignee?: string | string[]; role?: string; team?: string; priority?: Priority; timeout?: number; suggestions?: string[]; metadata?: Record; }): Promise; /** * Request a human to perform a task * * @example * ```ts * const result = await human.do({ * title: 'Review code', * instructions: 'Review the PR and provide feedback', * input: { prUrl: 'https://github.com/...' }, * assignee: 'senior-dev@example.com', * }) * ``` */ do(params: { title: string; instructions: string; input: TInput; assignee?: string | string[]; role?: string; team?: string; priority?: Priority; timeout?: number; tools?: any[]; estimatedEffort?: string; metadata?: Record; }): Promise; /** * Request a human to make a decision * * @example * ```ts * const choice = await human.decide({ * title: 'Pick deployment strategy', * options: ['blue-green', 'canary', 'rolling'], * context: { risk: 'high', users: 100000 }, * assignee: 'devops-lead@example.com', * }) * ``` */ decide(params: { title: string; description?: string; options: TOptions[]; context?: unknown; assignee?: string | string[]; role?: string; team?: string; priority?: Priority; timeout?: number; criteria?: string[]; metadata?: Record; }): Promise; /** * Request a human to review content * * @example * ```ts * const review = await human.review({ * title: 'Review blog post', * content: { title: 'My Post', body: '...' }, * reviewType: 'content', * criteria: ['Grammar', 'Tone', 'Accuracy'], * assignee: 'editor@example.com', * }) * ``` */ review(params: { title: string; description?: string; content: TContent; reviewType?: 'code' | 'content' | 'design' | 'data' | 'other'; criteria?: string[]; assignee?: string | string[]; role?: string; team?: string; priority?: Priority; timeout?: number; metadata?: Record; }): Promise; /** * Send a notification to a human * * @example * ```ts * await human.notify({ * type: 'info', * title: 'Deployment complete', * message: 'Version 2.0.0 deployed successfully', * recipient: 'team@example.com', * channels: ['slack', 'email'], * }) * ``` */ notify(params: { type: 'info' | 'warning' | 'error' | 'success'; title: string; message: string; recipient: string | string[]; channels?: ('slack' | 'email' | 'sms' | 'web')[]; priority?: Priority; data?: unknown; }): Promise; /** * Get a review queue * * @example * ```ts * const queue = await human.getQueue({ * name: 'Pending Approvals', * filters: { * status: ['pending'], * priority: ['high', 'critical'], * }, * }) * ``` */ getQueue(params: { name: string; description?: string; filters?: ReviewQueue['filters']; sortBy?: 'createdAt' | 'priority' | 'updatedAt'; sortDirection?: 'asc' | 'desc'; limit?: number; }): Promise; /** * Get a request by ID */ getRequest(id: string): Promise; /** * Complete a request with a response */ completeRequest(id: string, response: T['response']): Promise; /** * Reject a request */ rejectRequest(id: string, reason: string): Promise; /** * Escalate a request */ escalateRequest(id: string, to: string): Promise; /** * Cancel a request */ cancelRequest(id: string): Promise; /** * Define or update goals */ defineGoals(goals: Goal[]): Goal[]; /** * Track KPIs */ trackKPIs(kpi: KPI): KPI; /** * Define or update OKRs */ defineOKRs(okr: OKR): OKR; /** * Create an approval workflow */ createWorkflow(workflow: ApprovalWorkflow): ApprovalWorkflow; /** * Get a workflow by ID */ getWorkflow(id: string): ApprovalWorkflow | undefined; /** * Wait for a human response * * In a real implementation, this would: * 1. Poll the store for updates * 2. Listen for webhooks/events * 3. Handle timeouts and escalations * 4. Return the response when available * * For now, this throws an error to indicate manual completion is needed */ private waitForResponse; /** * Poll for request completion */ private pollForCompletion; } /** * Create a Human-in-the-loop manager instance * * @example * ```ts * import { Human } from 'human-in-the-loop' * * const human = Human({ * defaultTimeout: 3600000, // 1 hour * autoEscalate: true, * }) * ``` */ export declare function Human(options?: HumanOptions): HumanManager; //# sourceMappingURL=human.d.ts.map