UNPKG

semnet-snap-protocol

Version:

TypeScript reference implementation of the SNAP Protocol v1.1 - Agent Internet Edition

148 lines 3.9 kB
import type { Task, TaskCreateRequest, TaskUpdate, SNAPMessage, AgentID, JSONRPCRequest } from './types.js'; import { TaskStatus } from './types.js'; /** * Generate a unique task ID */ export declare function generateTaskId(): string; /** * Task builder for creating task requests */ export declare class TaskBuilder { private request; constructor(message: SNAPMessage); /** * Set callback URL for status updates */ callback(url: string): this; /** * Set task timeout in seconds */ timeout(seconds: number): this; /** * Set task priority */ priority(priority: 'low' | 'normal' | 'high'): this; /** * Add metadata */ metadata(metadata: Record<string, any>): this; /** * Build the task creation request */ build(): TaskCreateRequest; /** * Build as JSON-RPC request */ buildRPC(id?: string): JSONRPCRequest; } /** * Task manager for creating and updating tasks */ export declare class TaskManager { /** * Create a new task */ static create(message: SNAPMessage): TaskBuilder; /** * Create a task instance */ static createTask(request: TaskCreateRequest, agentId: AgentID): Task; /** * Update task status */ static updateTask(task: Task, update: TaskUpdate): Task; /** * Mark task as processing */ static startProcessing(task: Task, message?: string, estimatedCompletion?: string): Task; /** * Update task progress */ static updateProgress(task: Task, progress: number, message?: string): Task; /** * Complete task with result */ static complete(task: Task, result: SNAPMessage): Task; /** * Fail task with error */ static fail(task: Task, error: string): Task; /** * Cancel task */ static cancel(task: Task, reason?: string): Task; /** * Check if task is active (can be updated) */ static isActive(task: Task): boolean; /** * Check if task is completed (successfully or not) */ static isCompleted(task: Task): boolean; /** * Check if task is expired based on timeout */ static isExpired(task: Task): boolean; /** * Get task duration in seconds */ static getDuration(task: Task): number; /** * Estimate completion time based on progress */ static estimateCompletion(task: Task): string | null; } /** * Task utilities */ export declare class TaskUtils { /** * Create JSON-RPC request to get task status */ static getStatusRequest(taskId: string, rpcId?: string): JSONRPCRequest; /** * Create JSON-RPC request to cancel task */ static cancelRequest(taskId: string, reason?: string, rpcId?: string): JSONRPCRequest; /** * Create JSON-RPC request to list tasks */ static listRequest(filters?: { status?: TaskStatus; limit?: number; offset?: number; }, rpcId?: string): JSONRPCRequest; /** * Create task status update notification */ static createStatusUpdate(task: Task): JSONRPCRequest; /** * Validate task object */ static validate(task: any): Task; /** * Filter tasks by status */ static filterByStatus(tasks: Task[], status: TaskStatus): Task[]; /** * Sort tasks by creation date */ static sortByCreatedAt(tasks: Task[], descending?: boolean): Task[]; /** * Get task summary statistics */ static getStats(tasks: Task[]): { total: number; queued: number; processing: number; completed: number; failed: number; cancelled: number; averageDuration: number; }; } /** * Convenience function to create a task */ export declare function createTask(message: SNAPMessage): TaskBuilder; //# sourceMappingURL=task.d.ts.map