UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

194 lines (193 loc) 7.88 kB
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { t as resolveDefaultModelForAgent } from "./model-selection-config-BrdmmqKD.js"; import { n as normalizeMessageChannel } from "./message-channel-core-AaEWic-A.js"; import "./message-channel-BQrhwUEA.js"; import { E as resolveProviderReasoningOutputModeWithPlugin } from "./provider-runtime-BRJDPNgk.js"; import { r as detectRuntimeShell } from "./shell-utils-We_VISCR.js"; import "./model-selection-di2kjKCB.js"; import { _ as resolveChannelReactionGuidance, h as resolveChannelMessageToolHints, m as listChannelSupportedActions } from "./openclaw-tools-CNOZOjlX.js"; import { t as collectRuntimeChannelCapabilities } from "./runtime-capabilities-DSL-Cp6r.js"; import { t as resolveExecDefaults } from "./exec-defaults-CET-_UfH.js"; import { i as resolveRuntimeOsLabel } from "./os-summary-B440lihS.js"; import { t as buildSystemPromptParams } from "./system-prompt-params-mVMVoMfR.js"; import { t as getMachineDisplayName } from "./machine-name-YAXH0Lb7.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, chatType: params.chatType, 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 };