import { DatabaseInterface } from '@happyvertical/sql'; import { SmrtJob } from './smrt-job.js'; /** The MCP Tasks extension identifier implemented by this durable adapter. */ export declare const MCP_TASKS_EXTENSION = "io.modelcontextprotocol/tasks"; /** MCP task states defined by the Tasks extension. */ export type McpTaskStatus = 'working' | 'input_required' | 'completed' | 'cancelled' | 'failed'; /** Durable shape returned by `tasks/get` after the transport adds `resultType`. */ export interface McpTask { taskId: string; status: McpTaskStatus; createdAt: string; lastUpdatedAt: string; ttlMs: number; pollIntervalMs?: number; statusMessage?: string; result?: Record; error?: { code: number; message: string; }; } /** Arguments passed through an MCP tool action into its backing job. */ export interface CreateMcpTaskInput { objectType: string; objectId: string; method: string; /** Exact positional custom-action invocation produced by the MCP generator. */ invocationArgs: unknown[]; tenantId?: string | null; /** Optional agent constructor configuration retained by normal background jobs. */ agentConfig?: Record; timeout?: number; pollIntervalMs?: number; ttlMs?: number; } /** Internal persisted marker distinguishing task invocations from normal jobs. */ export interface McpTaskJobMarker { invocationArgs: unknown[]; pollIntervalMs: number; ttlMs: number; } /** Serialize a completed task exactly as an MCP CallToolResult. */ export declare function createMcpTaskResult(result: unknown): Record; /** Thrown when a task doesn't belong to the current task-store principal. */ export declare class McpTaskNotFoundError extends Error { constructor(taskId: string); } /** Cooperative cancellation observed by an operation awaiting task input. */ export declare class McpTaskCancelledError extends Error { constructor(taskId: string); } /** * Durable adapter between the MCP Tasks extension and `_smrt_jobs`. * * A task is a projection of exactly one job row: `task_id` is a unique * correlation key on the row and cancellation changes that same row. This is * intentionally not a second task table, which prevents an orphaned queued * job when a caller cancels an MCP task. */ export declare class McpTaskStore { private readonly collection; private readonly ownerId; private constructor(); readonly pollIntervalMs: number; readonly ttlMs: number; static create(db: DatabaseInterface, options?: { ownerId?: string | null; pollIntervalMs?: number; ttlMs?: number; }): Promise; /** Create one pending job and return its immediately-pollable task projection. */ createTask(input: CreateMcpTaskInput): Promise; /** Get a task only when it belongs to this store's principal. */ getTask(taskId: string): Promise; /** * Persist only values requested by an outstanding `requestInput()` call. * Unknown and already-consumed keys are intentionally ignored per SEP-2663. */ updateTask(taskId: string, inputResponses: Record): Promise; /** * Cooperatively cancel the backing job. A completion race cannot resurrect * it because TaskRunner terminal writes require `status = 'running'`. */ cancelTask(taskId: string): Promise; private findTaskJob; } /** Retrieve an internal task marker without exposing it to ordinary job callers. */ export declare function getMcpTaskMarker(job: Pick): McpTaskJobMarker | null; /** * Make a task operation wait for user input. It is intentionally a method on * JobExecutionContext rather than an MCP transport concern, so generated * stdio and stateless HTTP share one durable input seam. */ export declare function requestMcpTaskInput(db: DatabaseInterface, job: Pick, inputRequests: Record): Promise>; /** Convert the job state into the flat task shape required by `tasks/get`. */ export declare function taskFromJob(job: SmrtJob, marker: Pick): McpTask; //# sourceMappingURL=mcp-task.d.ts.map