"use client";
import { createContext, useContext, useRef, useSyncExternalStore } from "react";
import { ConversationStore } from "./conversation-store";
export { ConversationStore } from "./conversation-store";
export { structuralShare } from "./structural-share";
// ---------------------------------------------------------------------------
// Context
// ---------------------------------------------------------------------------
/**
 * Internal context for the conversation store. Not exported from the
 * public SDK barrel — used only within SDK hooks and components.
 */
export const ConversationStoreContext = createContext(null);
// ---------------------------------------------------------------------------
// Hooks
// ---------------------------------------------------------------------------
/**
 * Access the conversation store from context.
 * Throws if called outside a `ConversationStoreContext.Provider`.
 */
export function useConversationStore() {
    const store = useContext(ConversationStoreContext);
    if (!store) {
        throw new Error("useConversationStore must be used within a ConversationStoreContext.Provider");
    }
    return store;
}
/**
 * Create or reuse a `ConversationStore` instance. The store is
 * created once and preserved across re-renders via ref.
 */
export function useConversationStoreRef() {
    const ref = useRef(null);
    if (!ref.current) {
        ref.current = new ConversationStore();
    }
    return ref.current;
}
/**
 * Subscribe to the execution snapshot from the conversation store.
 * Returns a stable reference when the execution is unchanged
 * (structural sharing ensures this).
 */
export function useStoreExecution(store) {
    return useSyncExternalStore(store.subscribe, store.getExecution);
}
/**
 * Subscribe to the stream lifecycle state from the conversation store.
 * Returns a stable reference when the state is unchanged.
 */
export function useStoreStreamState(store) {
    return useSyncExternalStore(store.subscribe, store.getStreamState);
}
//# sourceMappingURL=index.js.map