/** * Agent Tools Factory - Creates and configures agent tools * * Centralizes tool creation logic to keep service.ts focused on orchestration. * * TTS: auto TTS is applied at the ChannelManager via maybeApplyTtsToPayload(). * Optional \`text_to_speech\` tool sends explicit voice when TTS is enabled. */ import type { AgentTool } from '@earendil-works/pi-agent-core'; import type { Model, Api } from '@earendil-works/pi-ai'; import type { Config } from '../../config/schema.js'; import type { EndpointToolRuntime } from '../../endpoint-tools/index.js'; import type { TurnOrigin } from '@xopcai/endpoint-tools-protocol'; import type { ExtensionRegistry } from '../../extensions/types/index.js'; import type { MessageBus } from '../../infra/bus/index.js'; import { type SkillInstallToolOptions, type SkillInstallToolResult, type MarketplaceSkillInstallToolOptions, type MarketplaceSkillInstallToolResult } from './index.js'; import { type DelegateTaskToolDeps } from './delegate-task-tool.js'; import type { SessionStore } from '../../session/store.js'; import type { GatewayClarifyRequestFn } from './clarify-tool.js'; import type { GatewaySecretRequestFn } from './request-secret-tool.js'; import { BrowserRuntime } from '../../browser/runtime/browser-runtime.js'; import type { EmbeddedBrowserGrantRegistry } from '../../browser/embedded/grant-registry.js'; import type { AutomationService } from '../../automations/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 { SkillManager } from '../skills/skill-manager.js'; import { type ToolExecutorConfig } from './executor.js'; export interface ToolFactoryDeps { isWorkspaceTrusted?: (workspaceDir: string) => boolean | null | undefined; workspace: string; extensionRegistry?: ExtensionRegistry; getCurrentContext: () => { channel: string; chatId: string; conversationId: string; origin: TurnOrigin; isGroup?: boolean; metadata?: Record; } | null; endpointTools?: EndpointToolRuntime; hookRunner?: import('../../extensions/index.js').ExtensionHookRunner; bus: MessageBus; toolExecutorConfig?: Partial; /** Agent defaults (image tools, etc.); use getter so hot-reloaded config applies. */ getConfig?: () => Config | undefined; /** Session / default chat model for vision tool description. */ getPrimaryModel?: () => Model; /** Skill runtime for the current workspace/session. */ getSkillManager?: () => SkillManager; getAgentToolAvailability?: DelegateTaskToolDeps['getAgentToolAvailability']; getAgentSkillAvailability?: DelegateTaskToolDeps['getAgentSkillAvailability']; /** Session store for `session_search`. */ getSessionStore?: () => SessionStore; /** When set (gateway webchat), enables the `clarify` tool. */ gatewayClarify?: { requestClarification: GatewayClarifyRequestFn; }; /** When set (gateway webchat), enables the `request_secret` tool. */ 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; }; /** Gateway: enables the `automation` tool. */ getAutomationService?: () => AutomationService | undefined; /** Gateway: enables the `chat_schedule` conversation follow-up tool. */ getChatScheduleService?: () => import('../../chat-schedules/index.js').ChatScheduleService | undefined; getCalendarService?: () => import('../../calendar/index.js').CalendarService | 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; deliverOutbound?: (msg: import('../../infra/bus/index.js').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?: EmbeddedBrowserGrantRegistry; /** Shared parent BrowserRuntime for delegated browser subagents (preserves live preview, host facts, and takeover). */ sharedBrowserRuntime?: { getRuntime: () => BrowserRuntime; taskKey: string; hasEmbeddedGrant?: () => boolean; }; /** Gateway: enables the `xopc_use` product-object tool. */ getNotesService?: () => NotesService | undefined; getProjectService?: () => ProjectService | undefined; getWorkDiscovery?: () => import('../../work-discovery/service.js').WorkDiscoveryService | undefined; getLocalAppService?: () => LocalAppService | undefined; getChatPreviewService?: () => import('../../chat-previews/index.js').ChatPreviewService | undefined; /** Gateway: publishes durable Task change notifications. */ dispatchTaskEvents?: () => void; /** Gateway: queues Task execution for xopc_use task start/resume/verify actions. */ dispatchTaskRuns?: () => void; retryTask?: import('../service.types.js').AgentServiceConfig['retryTask']; /** Gateway: refreshes Agent runtime state after xopc_use mutates the catalog. */ onAgentCatalogMutate?: () => void; /** Current session skill indexing (tool gating + allowlist); used by skills_list / skill_view. */ getSkillIndexingContext?: () => { registeredToolNames: string[]; skillAllowlist?: string[]; } | undefined; /** After skill_manage mutates disk, reload skills + refresh agent prompts (optional). */ onSkillsFilesystemMutate?: () => void; /** Names registered via skill_view for command env passthrough. */ getSkillPassthroughEnvVarNames?: () => string[]; /** Add declared env names for the current session (no values stored). */ registerSkillEnvPassthrough?: (names: string[]) => void; /** Install managed skills from explicit sources when a capability/tool enables it. */ installSkillFromSource?: (opts: SkillInstallToolOptions) => Promise; /** Install a managed skill from a built-in marketplace provider. */ installSkillFromMarketplace?: (opts: MarketplaceSkillInstallToolOptions) => Promise; } export interface CreateCoreToolsOptions { getParentTools?: () => AgentTool[]; createDelegationPolicy?: () => import('../orchestration/agent-turn-policy.js').AgentTurnPolicy; /** Workspace root for file/command tools (defaults to factory workspace). */ workspace?: string; /** Canonical `agents//profile/`: bare SOUL.md resolve here after the workspace. */ profileMarkdownRoot?: string; /** Tool `name` values to omit (e.g. `exec_command`, `extensions` for extension tools). */ disabledTools?: Set; /** Optional Agent-level allowlist of tool names. */ toolAllowlist?: readonly string[]; /** Optional primary model for image tool heuristics. */ getPrimaryModel?: () => Model; agentId?: string; conversationId?: string; /** When true, builds tool descriptors for catalog/availability inspection without mutating session metadata or wrapping execution hooks. */ inspectOnly?: boolean; /** When set, registers local skill tools plus marketplace discovery for this workspace. */ getSkillManager?: () => SkillManager; } export declare class AgentToolsFactory { private deps; private readonly candidateRegistrationCache; private getCandidateToolRegistration; getAgentRegisteredToolNames(candidateId: string): string[]; getAgentToolAvailability(candidateId: string, name: string): { condition: string; state: "verified" | "blocked"; reasonCode: string; detail: string; }; private browserRuntime; private attachedExtensionRuntime; private readonly deviceBrowserRuntimes; private readonly embeddedTabRuntimes; /** Cached readiness probe keyed by the active driver configuration. */ private browserReadinessCache; constructor(deps: ToolFactoryDeps); private prepareRuntimeEnv; private desktopManagedBrowserEndpointId; private browserReadinessKey; private hasBrowserEndpoint; private hasSandboxEndpoint; private hasArtifactCapableEndpoint; private checkBrowserReadinessCached; /** Invalidate the readiness cache (config hot-reload, settings-page save, etc.). */ invalidateBrowserReadinessCache(): void; private hasExplicitExtensionBinding; private ensureAttachedExtensionRuntime; private ensureBrowserRuntime; private deviceBrowserTarget; private embeddedBrowserGrantForCurrentRun; private embeddedTabRuntimeForCurrentRun; private closeEmbeddedTabRuntimes; private browserRuntimeForTurn; private reconcileStoppedDeviceBrowsers; private closeDeviceBrowserRuntimes; private computerRuntime?; private ensureComputerRuntime; hasBrowserSessions(): boolean; private closeBrowserResources; /** Close every independent resource even when one device cannot confirm stop. Failed runtimes remain quarantined. */ shutdownBrowser(): Promise; /** Drop the tab for a session when its agent instance is removed. */ closeBrowserPageForSession(conversationId: string): Promise; createCoreTools(options?: CreateCoreToolsOptions): AgentTool[]; private executorConfigFor; createCapabilityTools(capabilityNames: readonly string[], options?: Pick): AgentTool[]; getLazyCapabilityToolNames(): string[]; createAllTools(coreOptions?: CreateCoreToolsOptions): AgentTool[]; }