import { EventEmitter } from '@frontmcp/utils'; import type { FrontMcpLogger } from '../../common'; import type { SkillContent } from '../../common/interfaces'; import type { SkillLoadResult } from '../skill-storage.interface'; import type { SkillSessionStore } from './skill-session-store.interface'; import { type SkillActivationResult, type SkillPolicyMode, type SkillSecurityPolicy, type SkillSessionOptions, type SkillSessionState, type ToolAuthorizationResult } from './skill-session.types'; /** * Manages skill session state and tool authorization. * * Uses AsyncLocalStorage to track the active skill session per request context. * This ensures that tool authorization checks are isolated per MCP session. * * @example * ```typescript * const manager = new SkillSessionManager({ defaultPolicyMode: 'strict' }); * * // When loading a skill * const result = manager.activateSkill('review-pr', skillContent, loadResult); * * // When calling a tool * const authResult = manager.checkToolAuthorization('github_get_pr'); * if (!authResult.allowed) { * throw new ToolNotAllowedError(authResult); * } * * // When done with the skill * manager.deactivateSkill(); * ``` */ export declare class SkillSessionManager extends EventEmitter { private readonly storage; private readonly options; private readonly logger?; private readonly store?; constructor(options?: SkillSessionOptions, logger?: FrontMcpLogger, store?: SkillSessionStore); /** * Run a function within a skill session context. * The session state will be available via getActiveSession() within the callback. */ runWithSession(sessionId: string, fn: () => Promise): Promise; /** * Get the current session state. * Returns undefined if not running within a session context. */ getActiveSession(): SkillSessionState | undefined; /** * Check if there's an active skill in the current session. */ hasActiveSkill(): boolean; /** * Get the number of active skills in the current session. */ getActiveSkillCount(): number; /** * Get IDs of all active skills in the current session. */ getActiveSkillIds(): string[]; /** * Get names of all active skills in the current session. */ getActiveSkillNames(): string[]; /** * Activate a skill in the current session. * This adds the skill to the active skills and expands the tool allowlist. * Multiple skills can be active simultaneously, with their tool allowlists combined. * * @param skillId - The skill identifier * @param skillContent - The loaded skill content * @param loadResult - The skill load result with tool availability info * @param policy - Optional security policy override * @returns Activation result with session state and tool availability */ activateSkill(skillId: string, skillContent: SkillContent, loadResult: SkillLoadResult, policy?: SkillSecurityPolicy): SkillActivationResult; /** * Rebuild the combined allowedTools and requiredTools sets from all active skills. */ private rebuildCombinedToolSets; /** * Deactivate a skill or all skills in the current session. * * @param skillId - Optional skill ID to deactivate. If not provided, deactivates all skills. */ deactivateSkill(skillId?: string): void; /** * Clear all session state (called when no skills remain active). */ private clearSessionState; /** * Check if a tool is authorized in the current session. * Returns detailed authorization result including reason. * * @param toolName - The name of the tool to check * @returns Authorization result */ checkToolAuthorization(toolName: string): ToolAuthorizationResult; /** * Check if a tool is allowed without checking policy mode. * Simpler check for quick validation. */ isToolAllowed(toolName: string): boolean; /** * Get the list of tools allowed by the current skill. */ getToolAllowlist(): string[]; /** * Dynamically approve a tool for the current session. * Used when policyMode is 'approval' and user approves a tool. */ approveToolForSession(toolName: string): void; /** * Deny a tool for the current session. */ denyToolForSession(toolName: string): void; /** * Record a tool call in the session. * Updates the tool call count for rate limiting. */ recordToolCall(toolName: string): void; /** * Get the current policy mode. */ getPolicyMode(): string; /** * Set the policy mode for the current session. * Only applies if there's an active skill. */ setPolicyMode(mode: SkillPolicyMode): void; /** * Emit a session event. */ private emitSessionEvent; /** * Persist session state to store if available. */ private persistSession; } //# sourceMappingURL=skill-session.manager.d.ts.map