@agentman/chat-widget
Version:
Agentman Chat Widget for easy integration with web applications
80 lines (79 loc) • 2.45 kB
TypeScript
import type { PromptRule } from './types/types';
/**
* PromptManager handles dynamic prompt resolution based on URL patterns
*
* Features:
* - URL pattern matching (exact, startsWith, contains)
* - Priority-based rule resolution
* - Fallback to default prompts
*
* @example
* const manager = new PromptManager(rules, defaultPrompts);
* const prompts = manager.resolvePrompts('/products/zen-neo');
* // Returns: ['Product Q1', 'Product Q2', 'Product Q3']
*/
export declare class PromptManager {
private rules;
private defaultPrompts;
private staticPrompts;
private cache;
constructor(rules?: PromptRule[], defaultPrompts?: [string?, string?, string?], staticPrompts?: [string?, string?, string?]);
/**
* Resolve prompts for the given URL pathname
*
* Priority order:
* 1. Exact match rules
* 2. StartsWith match rules (longest pattern wins)
* 3. Contains match rules (first match wins)
* 4. Default prompts from rules
* 5. Static prompts (backward compatibility)
* 6. Empty array (no prompts)
*
* @param pathname - The URL pathname to match (e.g., '/products/zen-neo')
* @returns Array of 0-3 prompt strings
*/
resolvePrompts(pathname: string): [string?, string?, string?];
/**
* Find the best matching rule for the given pathname
*
* @param pathname - The URL pathname to match
* @returns The matching rule or undefined
*/
private findMatchingRule;
/**
* Check if pathname exactly matches the pattern
*/
private matchExact;
/**
* Check if pathname starts with the pattern
*/
private matchStartsWith;
/**
* Check if pathname contains the pattern
*/
private matchContains;
/**
* Update rules dynamically (clears cache)
*/
updateRules(rules: PromptRule[], defaultPrompts?: [string?, string?, string?], staticPrompts?: [string?, string?, string?]): void;
/**
* Clear the resolution cache
*/
clearCache(): void;
/**
* Get current rules
*/
getRules(): PromptRule[];
/**
* Get default prompts
*/
getDefaultPrompts(): [string?, string?, string?] | undefined;
/**
* Check if a specific URL would match any rules (useful for debugging)
*/
testUrl(pathname: string): {
matched: boolean;
rule?: PromptRule;
prompts: [string?, string?, string?];
};
}