import { Buffer } from "node:buffer";
//#region src/types.ts
/** Native clock backing the default (Date.now + crypto.randomUUID). */
const DEFAULT_AGENT_CLOCK = {
	now: () => Date.now(),
	randomUUID: () => crypto.randomUUID()
};
/**
* Render a short, human-readable marker for a document block.
*
* Used wherever a document attachment can't (or shouldn't) carry its raw bytes:
* - providers without document support degrade to a `[document omitted: …]` note,
* - the loop sanitizer strips bytes for non-capable models,
* - Anthropic emits an `[document attached: …]` note inside `tool_result` while
*   the bytes ride along as a sibling document block.
*
* `reason` is the prefix text after the leading bracket (e.g. `"document
* omitted"`); the helper appends the optional name, media type, and size so
* every call site shares one format instead of re-deriving the size label.
*/
function documentBlockMarker(doc, reason) {
	const sizeLabel = doc.encoding === "base64" ? `${doc.data.length} b64 bytes` : `${doc.data.length} chars`;
	return `[${reason}: ${doc.name ? `${doc.name}, ` : ""}${doc.mediaType}, ${sizeLabel}]`;
}
/**
* Lossy flattener — converts `ToolResultContent[]` (or a plain string) to a single
* string. Image blocks are replaced with `[image: <media> — <n> b64 bytes]` markers.
*
* Use at UI boundaries where a string is required; providers that understand
* structured content should route the array through without flattening.
*/
function toolResultToText(content) {
	if (typeof content === "string") return content;
	return content.map((block) => {
		if (block.type === "text") return block.text;
		if (block.type === "image") return `[image: ${block.mediaType} — ${block.data.length} b64 bytes]`;
		return `[document: ${block.mediaType} — ${block.data.length} ${block.encoding === "base64" ? "b64 bytes" : "chars"}${block.name ? ` — ${block.name}` : ""}]`;
	}).join("\n");
}
/**
* Approximate **text-budget size** of a tool output, in bytes.
*
* Structured attachment blocks count as the short markers produced by
* `toolResultToText`, not as raw base64 payload bytes. The per-turn
* `toolOutputBudget` is a readability/context-loading steering guard; a
* vision/PDF-capable provider can receive attachment bytes without needing the
* model to summarize them as if they were text output.
*/
function toolOutputBudgetByteLength(content) {
	return Buffer.byteLength(toolResultToText(content));
}
/**
* Approximate **wire payload size** of a tool output, in bytes.
*
* - Plain text: UTF-8 byte length.
* - Structured content: text blocks contribute their UTF-8 byte length; image
*   blocks contribute their **base64 character length** — a proxy for the
*   serialized request-body footprint, NOT for tokens. Vision encoders
*   tokenize decoded pixels (geometry-dependent; e.g. Anthropic ≈ `w·h/750`,
*   OpenAI ≈ 85 + 170/tile), which has no meaningful relationship to base64
*   length.
*
* Used by the agent loop to populate `outputBytes` on `tool:after`,
* `tool:transform`, `mcp:tool:after`, and `mcp:tool:transform` hooks so
* consumers can size-budget tool output without re-counting bytes themselves.
* Suitable for wire-size telemetry; the per-turn `toolOutputBudget` uses
* `toolOutputBudgetByteLength` so attachments do not trigger text-output
* summarization nudges by themselves. NOT a substitute for provider-side
* context-window accounting — defer to server-side context management (e.g.
* Anthropic's `context-management-*` beta) when token accuracy matters.
*/
function toolOutputByteLength(content) {
	if (typeof content === "string") return Buffer.byteLength(content);
	let total = 0;
	for (const block of content) if (block.type === "text") total += Buffer.byteLength(block.text);
	else if (block.type === "image") total += block.data.length;
	else total += block.data.length;
	return total;
}
//#endregion
export { toolResultToText as a, toolOutputByteLength as i, documentBlockMarker as n, toolOutputBudgetByteLength as r, DEFAULT_AGENT_CLOCK as t };

//# sourceMappingURL=types-BiobHM1D.js.map