// Streaming textual tool intent extractor (对齐)
// Detects <function=execute> blocks and structured apply_patch payloads
// and converts them into OpenAI tool_calls incrementally.
import { createStreamingToolExtractorStateWithNative, feedStreamingToolExtractorWithNative, resetStreamingToolExtractorStateWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
function assertStreamingToolExtractorNativeAvailable() {
    if (typeof createStreamingToolExtractorStateWithNative !== 'function' ||
        typeof resetStreamingToolExtractorStateWithNative !== 'function' ||
        typeof feedStreamingToolExtractorWithNative !== 'function') {
        throw new Error('[streaming-text-extractor] native bindings unavailable');
    }
}
export class StreamingTextToolExtractor {
    opts;
    state;
    constructor(opts = {}) {
        this.opts = opts;
        assertStreamingToolExtractorNativeAvailable();
        this.state = createStreamingToolExtractorStateWithNative(this.opts.idPrefix || 'call');
    }
    reset() {
        assertStreamingToolExtractorNativeAvailable();
        this.state = resetStreamingToolExtractorStateWithNative(this.state);
    }
    feedText(text) {
        if (typeof text !== 'string' || !text)
            return [];
        assertStreamingToolExtractorNativeAvailable();
        const output = feedStreamingToolExtractorWithNative({
            state: this.state,
            text,
            nowMs: Date.now()
        });
        this.state = output.state;
        return output.toolCalls;
    }
}
export function createStreamingToolExtractor(opts) {
    return new StreamingTextToolExtractor(opts);
}
