/** * 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 { MemoryManager } from '../memory/manager.js'; import type { SessionStore } from '../../session/store.js'; import type { GatewayClarifyRequestFn } from './clarify-tool.js'; import type { AutomationService } from '../../automations/index.js'; import type { BrowserRecipeService } from '../../browser/recipes/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 { WorkflowRunServiceLike } from '../../workflows/service/workflow-run-service.types.js'; import type { SkillManager } from '../skills/skill-manager.js'; import { type ToolExecutorConfig } from './executor.js'; export interface ToolFactoryDeps { workspace: string; extensionRegistry?: ExtensionRegistry; getCurrentContext: () => { channel: string; chatId: string; sessionKey: string; origin: TurnOrigin; } | 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; /** Memory orchestration (prefetch/sync + external tools). */ getMemoryManager?: () => MemoryManager; /** Session store for `session_search`. */ getSessionStore?: () => SessionStore; /** When set (gateway webchat), enables the `clarify` tool. */ gatewayClarify?: { requestClarification: GatewayClarifyRequestFn; }; /** Gateway: enables the `automation` tool. */ getAutomationService?: () => AutomationService | undefined; getBrowserRecipeService?: () => BrowserRecipeService | undefined; /** Gateway: enables the `xopc_use` product-object tool. */ getNotesService?: () => NotesService | undefined; getProjectService?: () => ProjectService | undefined; getLocalAppService?: () => LocalAppService | undefined; /** Gateway: queues Task execution for xopc_use task start/resume/verify actions. */ dispatchTaskRuns?: () => void; /** Gateway: starts persisted workflow runs (dedicated chat session per run). */ getWorkflowRunService?: () => WorkflowRunServiceLike | undefined; /** 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 { /** Workspace root for file/command tools (defaults to factory workspace). */ workspace?: string; /** Canonical `agents//profile/`: bare SOUL.md / IDENTITY.md resolve here after the workspace. */ profileMarkdownRoot?: string; /** Tool `name` values to omit (e.g. `exec_command`, `extensions` for extension tools). */ disabledTools?: Set; /** Optional primary model for image tool heuristics. */ getPrimaryModel?: () => Model; getMemoryManager?: () => MemoryManager; agentId?: string; /** When set, registers local skill tools plus marketplace discovery for this workspace. */ getSkillManager?: () => SkillManager; } export declare class AgentToolsFactory { private deps; private browserManager; /** One dialog/console supervisor per chat session (browser tab). */ private readonly browserTaskSupervisors; /** Cached readiness probe — keyed by backend mode + extension host:port. */ private browserReadinessCache; constructor(deps: ToolFactoryDeps); private prepareRuntimeEnv; private browserReadinessKey; private checkBrowserReadinessCached; /** Invalidate the readiness cache (config hot-reload, settings-page save, etc.). */ invalidateBrowserReadinessCache(): void; private browserSupervisorForTask; private acquireBrowserPage; private ensureBrowserManager; /** Close Playwright and all pages (gateway stop, agent manager dispose, or config hot-reload). */ shutdownBrowser(): Promise; /** Drop the tab for a session when its agent instance is removed. */ closeBrowserPageForSession(sessionKey: string): Promise; createCoreTools(options?: CreateCoreToolsOptions): AgentTool[]; createCapabilityTools(capabilityNames: readonly string[], options?: Pick): AgentTool[]; getLazyCapabilityToolNames(): string[]; createAllTools(coreOptions?: CreateCoreToolsOptions): AgentTool[]; }