import type { ThinkingLevel } from '@earendil-works/pi-agent-core'; import type { Config } from '../config/schema.js'; import type { OutboundMessage } from '../infra/bus/index.js'; import type { SessionStore } from '../session/store.js'; import type { AutomationService } from '../automations/index.js'; import type { ExtensionRegistryImpl as ExtensionRegistry } from '../extensions/index.js'; import type { NotesService } from '../notes/index.js'; import type { ProjectService } from '../projects/index.js'; import type { LocalAppService } from '../local-apps/index.js'; import type { ChatPreviewService } from '../chat-previews/index.js'; import type { GatewayClarifyRequestFn } from './tools/clarify-tool.js'; import type { GatewaySecretRequestFn } from './tools/request-secret-tool.js'; import type { AgentSourceContextResolver } from './source-context/types.js'; import type { EndpointToolRuntime } from '../endpoint-tools/index.js'; export interface AgentServiceConfig { workspace: string; model?: string; config?: Config; extensionRegistry?: ExtensionRegistry; endpointTools?: EndpointToolRuntime; maxRequestsPerTurn?: number; maxToolFailuresPerTurn?: number; maxTaskDurationMs?: number; thinkingLevel?: ThinkingLevel; reasoningLevel?: 'off' | 'on' | 'stream'; verboseLevel?: 'off' | 'on' | 'full'; /** * Gateway-only: blocks the `clarify` tool until the user answers via the web UI. */ gatewayClarify?: { requestClarification: GatewayClarifyRequestFn; }; /** * Gateway-only: pauses or resolves `request_secret` via the secret staging runtime. */ gatewaySecretRequest?: { requestSecret: GatewaySecretRequestFn; savePastedSecret?: (context: { conversationId: string; runId: string; toolCallId: string; }, input: { label: string; value: string; }) => Promise<{ file: string; }>; consumeSecretRef?: (input: { ref: string; conversationId: string; }) => Promise; }; getAutomationService?: () => AutomationService | undefined; getCalendarService?: () => import('../calendar/index.js').CalendarService | undefined; getChatScheduleService?: () => import('../chat-schedules/index.js').ChatScheduleService | undefined; getProactiveHubService?: () => import('../proactive-hub/triage-service.js').ProactiveHubService | undefined; getMatterInvestigator?: () => import('../proactive-hub/matter-investigator.js').MatterInvestigatorService | undefined; onMatterMutated?: (info: { matterId: string; kind: 'created' | 'updated' | 'resolved'; }) => void; canConfigureEndpoint?: (endpointId: string) => boolean; /** Gateway: direct verified outbound delivery for proactive cross-channel sends. */ deliverOutbound?: (msg: OutboundMessage) => Promise; getBrowserSetupService?: () => import('../browser/setup/service.js').BrowserSetupService | undefined; getMcpSetupService?: () => import('./mcp/conversation-setup.js').McpConversationSetup | undefined; getSelfConfigService?: () => import('../self-config/service.js').SelfConfigService | undefined; getSetupSceneService?: () => import('../self-config/setup-engine.js').UnifiedSetupSceneService | undefined; getCapabilityChannelState?: () => import('../capabilities/capability-catalog.js').CapabilityChannelState; emitBrowserEvent?: (type: string, payload: unknown) => void; embeddedBrowserGrants?: import('../browser/embedded/grant-registry.js').EmbeddedBrowserGrantRegistry; /** Gateway: exposes first-class xopc product objects for the `xopc_use` tool. */ getNotesService?: () => NotesService | undefined; getProjectService?: () => ProjectService | undefined; getWorkDiscovery?: () => import('../work-discovery/service.js').WorkDiscoveryService | undefined; getLocalAppService?: () => LocalAppService | undefined; getChatPreviewService?: () => ChatPreviewService | undefined; dispatchTaskEvents?: () => void; dispatchTaskRuns?: () => void; retryTask?: (input: import('../tasks/task-retry-service.js').TaskRetryInput) => Promise; /** Gateway: refresh runtime state and notify clients after a conversational Agent mutation. */ onAgentCatalogMutate?: () => void; /** * Gateway: reuse the gateway `SessionManager` store so web API and agent share one index + files. * When omitted, `AgentService` creates its own `SessionStore` (CLI / embedded). */ sessionStore?: SessionStore; onSessionMetadataUpdated?: (conversationId: string, patch?: { name?: string; }) => void; /** Gateway: transcript append notification. */ onSessionTranscriptUpdated?: (conversationId: string) => void; /** Gateway/TUI: local skill catalog changed or skill config toggles changed. */ onSkillsUpdated?: (payload: { reason: 'disk' | 'config'; }) => void; /** * Runtime trust override. Local TUI uses this to trust the startup workspace * without persisting a trust entry; gateway mode leaves trust fully persistent. */ isWorkspaceTrusted?: (workspaceDir: string) => boolean | null | undefined; /** Gateway: resolves bound source context (e.g. Note-grounded chat) before each turn. */ sourceContextResolver?: AgentSourceContextResolver; } export interface AgentContext { channel: string; chatId: string; conversationId: string; senderId?: string; isGroup?: boolean; } export interface StreamHandle { update: (text: string) => void; end: () => Promise; abort: () => Promise; messageId: () => number | undefined; }