/** * a2a/tasks.ts — the Task store behind AIBroker's A2A server. * * Pure functions over a JSON file, path-injectable so tests never touch the * real store. Three properties the spec does not hand you for free and a * naive implementation gets wrong: * * IDEMPOTENCY. Spec 6.4 gives every Message a `messageId`, generated by the * sender. A client that retries a `message/send` after a timeout must not * spawn a second task for work already accepted — `findByMessageId` is * checked before a new task is created, so the same id always resolves to * the same task. * * THREADING. `contextId` groups a multi-turn conversation (spec 6.1, 6.4). * A second message carrying a contextId whose task is still open (not in a * terminal state) is appended to that task's history rather than starting a * new one — the same session keeps the thread instead of forking a new task * per reply. * * BOUNDED AND EXPIRED. Capped at 500 tasks; terminal tasks older than 7 days * are swept by `cleanupExpired`. Eviction prefers the oldest TERMINAL task * over the oldest task outright, so a burst of short-lived tasks does not * push out something still `working`. */ import type { TaskState } from "./schema/types.js"; export type { TaskState } from "./schema/types.js"; export interface TaskHistoryEntry { role: "user" | "agent"; text: string; messageId: string; at: string; } export interface TaskArtifactEntry { artifactId: string; name?: string; text: string; /** Set when the artifact's text was validated as an AG2 message and passed. */ agentishOk?: boolean; } export interface A2ATask { id: string; contextId: string; /** The exposed session this task was addressed to. */ session: string; state: TaskState; statusMessage?: string; createdAt: string; updatedAt: string; history: TaskHistoryEntry[]; artifacts: TaskArtifactEntry[]; } export declare function defaultTaskFile(): string; export declare function findByMessageId(messageId: string, file?: string): A2ATask | undefined; export declare function getTask(id: string, file?: string): A2ATask | undefined; export declare function listForSession(session: string, file?: string): A2ATask[]; export declare function listAll(file?: string): A2ATask[]; export interface CreateOrThreadResult { task: A2ATask; /** False when an existing open task on the same contextId was reused. */ created: boolean; } /** * Create a task for `session`, or thread onto an existing open one sharing * `contextId`, or return the task a repeated `messageId` already produced. */ export declare function createOrThreadTask(opts: { session: string; text: string; messageId: string; contextId?: string; }, file?: string): CreateOrThreadResult; export declare function setStatus(id: string, state: TaskState, opts?: { message?: string; }, file?: string): A2ATask | undefined; export declare function addArtifact(id: string, text: string, opts?: { name?: string; agentishOk?: boolean; }, file?: string): A2ATask | undefined; /** Remove terminal tasks past EXPIRY_MS. Returns how many were removed. */ export declare function cleanupExpired(file?: string, now?: number): number; //# sourceMappingURL=tasks.d.ts.map