capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
37 lines • 1.3 kB
JavaScript
import { EventEmitter } from 'events';
export class ToolResultsService extends EventEmitter {
pendingResults = new Map();
resultPromises = new Map();
resultResolvers = new Map();
setToolResult(callId, result) {
this.pendingResults.set(callId, result);
const resolver = this.resultResolvers.get(callId);
if (resolver) {
resolver(result);
this.resultResolvers.delete(callId);
this.resultPromises.delete(callId);
}
this.emit('tool-result', callId, result);
}
async waitForToolResult(callId) {
const existing = this.pendingResults.get(callId);
if (existing) {
this.pendingResults.delete(callId);
return existing;
}
if (!this.resultPromises.has(callId)) {
const promise = new Promise((resolve) => {
this.resultResolvers.set(callId, resolve);
});
this.resultPromises.set(callId, promise);
}
return this.resultPromises.get(callId);
}
clearOldResults() {
this.pendingResults.clear();
this.resultPromises.clear();
this.resultResolvers.clear();
}
}
export const toolResultsService = new ToolResultsService();
//# sourceMappingURL=tool-results.js.map