UNPKG

@wavequery/conductor

Version:
70 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextManager = void 0; class ContextManager { constructor(store, contextId) { this.store = store; this.contextId = contextId; this.context = { messages: [], metadata: {}, state: {}, }; } async initialize() { const savedContext = await this.store.recall(this.contextId); if (savedContext) { this.context = savedContext; } } async addMessage(role, content) { this.context.messages.push({ role, content, timestamp: new Date(), }); await this.save(); } async updateMetadata(metadata) { this.context.metadata = { ...this.context.metadata, ...metadata, }; await this.save(); } async setState(key, value) { this.context.state[key] = value; await this.save(); } async getState(key) { return this.context.state[key]; } getRecentMessages(count = 10) { return this.context.messages.slice(-count); } async summarize() { return { messageCount: this.context.messages.length, lastMessageTime: this.context.messages.length > 0 ? this.context.messages[this.context.messages.length - 1].timestamp : null, metadata: this.context.metadata, }; } async save() { await this.store.remember(this.contextId, this.context, { type: "context", tags: ["context", this.contextId], }); } async clear() { this.context = { messages: [], metadata: {}, state: {}, }; await this.save(); } } exports.ContextManager = ContextManager; //# sourceMappingURL=context-manager.js.map