UNPKG

@kddd/artinet-sdk

Version:

TypeScript SDK for the Agent2Agent (A2A) Protocol

42 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InMemoryTaskStore = void 0; const log_js_1 = require("../../../utils/logging/log.js"); /** * In-memory implementation of the TaskStore interface. * Stores tasks and their history in memory. Not persisted between server restarts. */ class InMemoryTaskStore { store = new Map(); /** * Loads a task and its history by task ID. * @param taskId The ID of the task to load. * @returns A promise resolving to the task and history, or null if not found. */ async load(taskId) { (0, log_js_1.logDebug)("InMemoryTaskStore", `Loading task: ${taskId}`); const entry = this.store.get(taskId); // Return copies to prevent external mutation return entry ? { task: { ...entry.task }, history: [...entry.history], } : null; } /** * Saves a task and its history. * @param data The task and history to save. * @returns A promise that resolves when the save is complete. */ async save(data) { (0, log_js_1.logDebug)("InMemoryTaskStore", `Saving task: ${data.task.id}`); // Store copies to prevent internal mutation if caller reuses objects this.store.set(data.task.id, { task: { ...data.task }, history: [...data.history], }); } } exports.InMemoryTaskStore = InMemoryTaskStore; //# sourceMappingURL=memory.js.map