import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js";
import { r as resolveDefaultModelForAgent } from "./codex-plugin-diagnostics-dOUrXvwq.js";
import { n as normalizeMessageChannel } from "./message-channel-core-DpLp0BgI.js";
import "./message-channel-B5ay7uNh.js";
import { T as resolveProviderReasoningOutputModeWithPlugin } from "./provider-runtime-8UHaPmAy.js";
import { r as detectRuntimeShell } from "./shell-utils-DAgUwgg-.js";
import "./model-selection-CtjI2iP7.js";
import { f as listChannelSupportedActions, h as resolveChannelReactionGuidance, p as resolveChannelMessageToolHints } from "./openclaw-tools-B6oAovn4.js";
import { t as collectRuntimeChannelCapabilities } from "./runtime-capabilities-tBQnVb-6.js";
import { t as resolveExecDefaults } from "./exec-defaults-BKYXT0iU.js";
import { i as resolveRuntimeOsLabel } from "./os-summary-q1rQKLEc.js";
import { t as buildSystemPromptParams } from "./system-prompt-params-ltRWo8Rl.js";
import { t as getMachineDisplayName } from "./machine-name-h6n2E7QY.js";
import os from "node:os";
//#region src/utils/provider-utils.ts
/**
* Provider behavior helpers shared by reply runners, embedded agents, and provider plugins.
* Keep policy here generic; provider-specific reasoning rules belong in provider runtime hooks.
*/
/**
* Resolves whether a provider should emit reasoning via native fields or tagged text,
* using provider runtime hooks when available and defaulting to native output.
*/
function resolveReasoningOutputMode(params) {
	const provider = normalizeOptionalString(params.provider);
	if (!provider) return "native";
	const pluginMode = resolveProviderReasoningOutputModeWithPlugin({
		provider,
		config: params.config,
		workspaceDir: params.workspaceDir,
		env: params.env,
		runtimeHandle: params.runtimeHandle,
		context: {
			config: params.config,
			workspaceDir: params.workspaceDir,
			env: params.env,
			provider,
			modelId: params.modelId,
			modelApi: params.modelApi,
			model: params.model
		}
	});
	if (pluginMode) return pluginMode;
	return "native";
}
/**
* Returns true if the provider requires reasoning to be wrapped in tags
* (e.g. <think> and <final>) in the text stream, rather than using native
* API fields for reasoning/thinking.
*/
function isReasoningTagProvider(provider, options) {
	return resolveReasoningOutputMode({
		provider,
		config: options?.config,
		workspaceDir: options?.workspaceDir,
		env: options?.env,
		modelId: options?.modelId,
		modelApi: options?.modelApi,
		model: options?.model,
		runtimeHandle: options?.runtimeHandle
	}) === "tagged";
}
//#endregion
//#region src/agents/runtime-prompt.ts
async function resolveAgentRuntimePrompt(params) {
	const runtimeChannel = normalizeMessageChannel(params.channel);
	const channelPromptContext = {
		cfg: params.config,
		channel: runtimeChannel,
		accountId: params.accountId
	};
	const runtimeCapabilities = collectRuntimeChannelCapabilities(channelPromptContext);
	const reactionGuidance = runtimeChannel && params.config ? resolveChannelReactionGuidance(channelPromptContext) : void 0;
	const messageToolHints = runtimeChannel ? resolveChannelMessageToolHints(channelPromptContext) : void 0;
	const channelActions = runtimeChannel ? listChannelSupportedActions({
		cfg: params.config,
		channel: runtimeChannel,
		currentChannelId: params.currentChannelId ?? void 0,
		currentThreadTs: params.currentThreadTs ?? void 0,
		currentMessageId: params.currentMessageId ?? void 0,
		accountId: params.accountId ?? void 0,
		sessionKey: params.sessionKey ?? void 0,
		sessionId: params.sessionId ?? void 0,
		agentId: params.agentId ?? void 0,
		requesterSenderId: params.senderId ?? void 0,
		senderIsOwner: params.senderIsOwner ?? void 0
	}) : void 0;
	const defaultModel = resolveDefaultModelForAgent({
		cfg: params.config ?? {},
		agentId: params.agentId
	});
	const machineName = await getMachineDisplayName();
	return {
		...buildSystemPromptParams({
			config: params.config,
			agentId: params.agentId,
			workspaceDir: params.workspaceDir,
			cwd: params.cwd,
			...Object.hasOwn(params, "preparedRepoRoot") ? { preparedRepoRoot: params.preparedRepoRoot } : {},
			runtime: {
				sessionKey: params.sessionKey,
				sessionId: params.sessionId,
				host: machineName,
				os: resolveRuntimeOsLabel(),
				arch: os.arch(),
				node: process.version,
				model: params.model,
				defaultModel: `${defaultModel.provider}/${defaultModel.model}`,
				shell: detectRuntimeShell(),
				channel: runtimeChannel,
				chatType: params.chatType,
				capabilities: runtimeCapabilities,
				channelActions,
				activeProcessSessions: params.activeProcessSessions
			}
		}),
		runtimeChannel,
		runtimeCapabilities,
		reactionGuidance,
		messageToolHints
	};
}
//#endregion
//#region src/agents/embedded-agent-runner/sandbox-info.ts
function execPolicyBlocksFullAccess(params) {
	return params.execPolicy?.mode !== void 0 && params.execPolicy.mode !== "full" || params.execPolicy?.security !== void 0 && params.execPolicy.security !== "full" || params.execPolicy?.ask !== void 0 && params.execPolicy.ask === "always" || params.hostPolicy?.security !== void 0 && params.hostPolicy.security !== "full" || params.hostPolicy?.ask !== void 0 && params.hostPolicy.ask === "always";
}
/** Computes whether elevated exec can provide full host access for an embedded turn. */
function resolveEmbeddedFullAccessState(params) {
	if (execPolicyBlocksFullAccess(params)) return {
		available: false,
		blockedReason: "host-policy"
	};
	if (params.execElevated?.fullAccessAvailable === true) return { available: true };
	if (params.execElevated?.fullAccessAvailable === false) return {
		available: false,
		blockedReason: params.execElevated.fullAccessBlockedReason ?? "host-policy"
	};
	if (!params.execElevated?.enabled || !params.execElevated.allowed) return {
		available: false,
		blockedReason: "host-policy"
	};
	return { available: true };
}
/** Resolves the effective exec policy for sandbox-info reporting. */
function resolveEmbeddedSandboxInfoExecPolicy(params) {
	const defaults = resolveExecDefaults({
		cfg: params.config,
		agentId: params.agentId,
		sessionKey: params.sessionKey,
		sessionEntry: params.permissionMode ? { permissionMode: params.permissionMode } : void 0,
		sandboxAvailable: params.sandboxAvailable,
		elevatedRequested: true,
		execOverrides: params.execOverrides
	});
	return {
		mode: defaults.mode,
		security: defaults.security,
		ask: defaults.ask
	};
}
/** Builds the serializable sandbox metadata attached to embedded agent run results. */
function buildEmbeddedSandboxInfo(sandbox, execElevated, execPolicy, hostPolicy) {
	if (!sandbox?.enabled) return;
	const elevatedConfigured = execElevated?.enabled === true;
	const elevatedAllowed = !sandbox.required && Boolean(execElevated?.enabled && execElevated.allowed);
	const fullAccess = sandbox.required ? {
		available: false,
		blockedReason: "host-policy"
	} : resolveEmbeddedFullAccessState({
		execElevated,
		execPolicy,
		hostPolicy
	});
	return {
		enabled: true,
		workspaceDir: sandbox.workspaceDir,
		containerWorkspaceDir: sandbox.containerWorkdir,
		workspaceAccess: sandbox.workspaceAccess,
		agentWorkspaceMount: sandbox.workspaceAccess === "ro" ? "/agent" : void 0,
		browserBridgeUrl: sandbox.browser?.bridgeUrl,
		hostBrowserAllowed: sandbox.browserAllowHostControl,
		...elevatedConfigured ? { elevated: {
			allowed: elevatedAllowed,
			defaultLevel: sandbox.required ? "off" : execElevated?.defaultLevel ?? "off",
			fullAccessAvailable: fullAccess.available,
			...fullAccess.blockedReason ? { fullAccessBlockedReason: fullAccess.blockedReason } : {}
		} } : {}
	};
}
//#endregion
export { isReasoningTagProvider as a, resolveAgentRuntimePrompt as i, resolveEmbeddedFullAccessState as n, resolveEmbeddedSandboxInfoExecPolicy as r, buildEmbeddedSandboxInfo as t };
