import {streamDynamicAiResponse} from '@/features/loyaly-ai/services/ai/mockAi';
import type {ChatMessage, MessagePart} from '@/features/loyaly-ai/types/chat';

export interface StreamRequest {
  prompt: string;
  history: ChatMessage[];
  signal?: AbortSignal;
}

export const loyalyAiRepository = {
  /**
   * Stream dynamic assistant answers based on prompt classification & entity routing.
   */
  async *streamReply({
    prompt,
    history,
    signal,
  }: StreamRequest): AsyncGenerator<MessagePart, void, undefined> {
    for await (const part of streamDynamicAiResponse(prompt, history, signal)) {
      if (signal?.aborted) return;
      yield part;
    }
  },
};
