PromptStrategyManager.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { GhostSuggestionContext } from "./types"
  2. import { PromptStrategy } from "./types/PromptStrategy"
  3. // Import all strategies
  4. import { AutoTriggerStrategy } from "./strategies/AutoTriggerStrategy"
  5. /**
  6. * Manages prompt strategies and selects the appropriate one based on context
  7. */
  8. export class PromptStrategyManager {
  9. private autoTriggerStrategy: AutoTriggerStrategy
  10. private debug: boolean
  11. constructor(options?: { debug?: boolean }) {
  12. this.debug = options?.debug ?? false
  13. this.autoTriggerStrategy = new AutoTriggerStrategy()
  14. }
  15. /**
  16. * Selects the most appropriate strategy for the given context
  17. * @param context The suggestion context
  18. * @returns The selected strategy
  19. */
  20. selectStrategy(context: GhostSuggestionContext): PromptStrategy {
  21. return this.autoTriggerStrategy
  22. }
  23. getAvailableStrategies(): string[] {
  24. return [this.autoTriggerStrategy.name]
  25. }
  26. /**
  27. * Builds complete prompts using the selected strategy
  28. * @param context The suggestion context
  29. * @returns Object containing system and user prompts
  30. */
  31. buildPrompt(context: GhostSuggestionContext): {
  32. systemPrompt: string
  33. userPrompt: string
  34. strategy: PromptStrategy
  35. } {
  36. const strategy = this.autoTriggerStrategy
  37. const { systemPrompt, userPrompt } = this.autoTriggerStrategy.getPrompts(context)
  38. if (this.debug) {
  39. console.log("[PromptStrategyManager] Prompt built:", {
  40. strategy: strategy.name,
  41. systemPromptLength: systemPrompt.length,
  42. userPromptLength: userPrompt.length,
  43. totalTokensEstimate: Math.ceil((systemPrompt.length + userPrompt.length) / 4),
  44. })
  45. }
  46. return {
  47. systemPrompt,
  48. userPrompt,
  49. strategy,
  50. }
  51. }
  52. }