"use client";
import { useMemo } from "react";
import { useArtifactContent } from "./useArtifactContent.js";
import { execIdFromStorageKey } from "./useFileChangeContent.js";
/**
 * Behavior hook that resolves the full text of a tool output that the runner
 * offloaded to artifact storage (a {@link ToolCallOutputRef}).
 *
 * Mirrors {@link useFileChangeContent}: it ignores any URL baked into the ref
 * and fetches the bytes on demand through the CORS-safe `getArtifactContent`
 * endpoint, deriving the execution id from the ref's own `storageKey`
 * (`artifacts/{executionId}/...`). This is what lets a "View full output" link
 * keep working long after the original presigned URL would have expired.
 *
 * Fetching is gated by `enabled` so callers can defer the request until the
 * user actually expands the output (lazy), keeping long threads cheap.
 *
 * @param outputRef - The offloaded-output reference, or `null` to skip.
 * @param enabled - When `false`, the hook stays idle. Defaults to `true`.
 *
 * @see useArtifactContent — the underlying content fetch
 * @see useArtifactDownloadUrl — for the truncated/binary full-download fallback
 */
export function useToolOutputContent(outputRef, enabled = true) {
    const storageKey = outputRef?.storageKey || null;
    const active = enabled && !!storageKey;
    const executionId = active ? execIdFromStorageKey(storageKey) : null;
    const { content, isLoading, isTruncated, error } = useArtifactContent(active ? executionId : null, active ? storageKey : null, null, outputRef?.contentHash || undefined);
    return useMemo(() => ({ content, isLoading, isTruncated, error }), [content, isLoading, isTruncated, error]);
}
//# sourceMappingURL=useToolOutputContent.js.map