UNPKG

@memberjunction/a2aserver

Version:

MemberJunction Agent-To-Agent (A2A) Server Implementation

86 lines 2.84 kB
import { IShutdownable } from "@memberjunction/global"; export type TaskStatus = 'pending' | 'in_progress' | 'completed' | 'cancelled' | 'failed'; export interface Part { id: string; type: 'text' | 'file' | 'data'; content: string | object; metadata?: object; } export interface Message { id: string; taskId: string; role: 'user' | 'agent'; parts: Part[]; created: Date; } export interface Artifact { id: string; taskId: string; name: string; parts: Part[]; created: Date; } export interface Task { id: string; status: TaskStatus; messages: Message[]; artifacts: Artifact[]; created: Date; updated: Date; } /** * Terminal task statuses — tasks in these states are eligible for cleanup * after the retention window elapses. */ export declare const TERMINAL_STATUSES: ReadonlySet<TaskStatus>; export interface TaskStoreOptions { /** How often to scan for terminal tasks. Default 5 minutes. */ sweepIntervalMs?: number; /** How long a terminal task is retained before sweep removes it. Default 1 hour. */ retentionMs?: number; } /** * Bounded in-memory task store with periodic terminal-state cleanup. * * Replaces the unbounded module-level `Map<string, Task>` that was the single * largest leak found in the audit (R2-C11): tasks accumulated forever with * their `messages[]` and `artifacts[]` arrays, growing memory roughly as * `tasks × messages × artifact-bytes`. The store keeps the same `Map`-like * surface (`set`/`get`/`delete`/`has`/`size`) so callers don't change, and * adds a sweeper that drops tasks in terminal state older than `retentionMs`. * Implements `IShutdownable` so the sweeper timer is cleared during graceful * shutdown. */ export declare class TaskStore implements IShutdownable { private readonly _tasks; private readonly _sweepIntervalMs; private readonly _retentionMs; private _timer; constructor(options?: TaskStoreOptions); get ShutdownName(): string; /** * Begin the periodic sweep. Idempotent; calling twice is safe. Uses `unref()` * so the sweep timer doesn't hold the process alive on its own. */ Start(): void; /** * Stop the sweep timer and drop all tasks. Idempotent. */ Shutdown(): void; /** * Configured retention window in milliseconds. */ get RetentionMs(): number; /** * Drop terminal-state tasks that haven't been updated in `retentionMs`. * Returns the count evicted (useful for tests and diagnostics). */ Sweep(now?: number): number; set(id: string, task: Task): this; get(id: string): Task | undefined; has(id: string): boolean; delete(id: string): boolean; get size(): number; values(): IterableIterator<Task>; } //# sourceMappingURL=TaskStore.d.ts.map