UNPKG

hataraku

Version:

An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.

74 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryThreadStorage = void 0; const thread_1 = require("./thread"); /** * In-memory implementation of ThreadStorage interface. * Stores thread states in a Map for temporary persistence during runtime. */ class MemoryThreadStorage { /** * Internal storage for thread states, keyed by thread ID. * @private */ threads = new Map(); /** * Creates a new instance of MemoryThreadStorage. */ constructor() { } /** * Saves a thread state to the in-memory storage. * @param state - The thread state to save * @returns A promise that resolves when the state has been saved */ async save(state) { this.threads.set(state.id, state); } /** * Creates a new thread with optional ID. * @param threadId - Optional ID for the thread. If not provided, one will be generated. * @returns A new Thread instance */ create(threadId) { return new thread_1.Thread({ storage: this, id: threadId }); } /** * Loads an existing thread by ID from memory. * @param threadId - The ID of the thread to load * @returns The loaded Thread instance * @throws Error if the thread with the specified ID is not found */ load(threadId) { const state = this.threads.get(threadId); if (!state) { throw new Error(`Thread not found: ${threadId}`); } return new thread_1.Thread({ storage: this, state }); } /** * Deletes a thread from memory by ID. * @param threadId - The ID of the thread to delete * @returns true if the thread was found and deleted, false otherwise */ delete(threadId) { return this.threads.delete(threadId); } /** * Removes all threads from memory storage. */ clear() { this.threads.clear(); } /** * Lists all thread IDs currently stored in memory. * @returns An array of thread IDs */ list() { return Array.from(this.threads.keys()); } } exports.MemoryThreadStorage = MemoryThreadStorage; //# sourceMappingURL=memory-storage.js.map