import { StreamHelper } from "../utils/stream-helpers.js";
import { StreamPart } from "./ArtifactParser.js";
import { FullExecutionContext } from "@inkeep/agents-core";

//#region src/domains/run/services/IncrementalStreamParser.d.ts

/**
 * Incremental parser that processes streaming text and formats artifacts/objects as they become complete
 * Uses the unified ArtifactParser to eliminate redundancy
 */
declare class IncrementalStreamParser {
  private buffer;
  private pendingTextBuffer;
  private streamHelper;
  private artifactParser;
  private hasStartedRole;
  private collectedParts;
  private contextId;
  private lastChunkWasToolResult;
  private componentAccumulator;
  private lastStreamedComponents;
  private componentSnapshots;
  private artifactMap?;
  private subAgentId?;
  private allStreamedContent;
  private static readonly MAX_SNAPSHOT_SIZE;
  private static readonly MAX_STREAMED_SIZE;
  private static readonly MAX_COLLECTED_PARTS;
  constructor(streamHelper: StreamHelper, executionContext: FullExecutionContext, contextId: string, artifactParserOptions?: {
    sessionId?: string;
    taskId?: string;
    artifactComponents?: any[];
    streamRequestId?: string;
    subAgentId?: string;
  });
  /**
   * Initialize artifact map for artifact:ref lookups during streaming
   * Should be called before processing chunks
   */
  initializeArtifactMap(): Promise<void>;
  /**
   * Mark that a tool result just completed, so next text should have spacing
   */
  markToolResult(): void;
  /**
   * Process a new text chunk for text streaming (handles artifact markers)
   */
  processTextChunk(chunk: string): Promise<void>;
  /**
   * Process object deltas directly from Vercel AI SDK's fullStream
   * Accumulates components and streams them when they're stable (unchanged between deltas)
   */
  processObjectDelta(delta: any): Promise<void>;
  /**
   * Stream a component and mark it as streamed
   * Note: Text components are handled separately with incremental streaming
   */
  private streamComponent;
  /**
   * Check if a component has the basic structure required for streaming
   * Requires id, name, and props object with content
   */
  private isComponentComplete;
  /**
   * Deep merge helper for object deltas
   */
  private deepMerge;
  /**
   * Legacy method for backward compatibility - defaults to text processing
   */
  processChunk(chunk: string): Promise<void>;
  /**
   * Process any remaining buffer content at the end of stream
   */
  finalize(): Promise<void>;
  /**
   * Get all collected parts for building the final response
   */
  getCollectedParts(): StreamPart[];
  /**
   * Get all streamed content that was actually sent to the user
   */
  getAllStreamedContent(): StreamPart[];
  /**
   * Parse buffer for complete artifacts and text parts (for text streaming)
   */
  private parseTextBuffer;
  /**
   * Check if text might be the start of an artifact marker
   */
  private mightBeArtifactStart;
  /**
   * Stream a formatted part (text or data) with smart buffering
   */
  private streamPart;
}
//#endregion
export { IncrementalStreamParser };