@toolplex/client
Version:
The official ToolPlex client for AI agent tool discovery and execution
52 lines (51 loc) • 1.21 kB
JavaScript
export class PromptsCache {
constructor() {
this._prompts = null;
this._version = null;
this._prompts = null;
this._version = null;
}
/**
* Initialize prompts cache with prompts from init response
*/
init(prompts) {
// Allow re-init.
this._prompts = prompts;
this._version = prompts._version;
}
/**
* Get a specific prompt by key from the cache
*/
getPrompt(key) {
if (!this._prompts) {
throw new Error("PromptsCache not initialized");
}
const prompt = this._prompts[key];
if (!prompt) {
throw new Error(`Prompt "${key}" not found in cache`);
}
return prompt;
}
/**
* Get the version of the current prompts
*/
getVersion() {
if (!this._version) {
throw new Error("PromptsCache not initialized");
}
return this._version;
}
/**
* Check if the cache is initialized
*/
isInitialized() {
return this._prompts !== null;
}
/**
* Reset the cache
*/
reset() {
this._prompts = null;
this._version = null;
}
}