import { resolveAgentWorkspaceDir } from "../../agents/agent-scope-config.js"; import { resolveSessionAgentId } from "../../agents/agent-scope.js"; import type { ReplyPayload } from "../../auto-reply/reply-payload.js"; import { normalizeReplyPayload } from "../../auto-reply/reply/normalize-reply.js"; import { createReplyMediaPathNormalizer } from "../../auto-reply/reply/reply-media-paths.runtime.js"; import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js"; import { createReplyPrefixContext } from "../../channels/reply-prefix.js"; import { createOutboundSendDeps, type CliDeps } from "../../cli/outbound-send-deps.js"; import type { SessionEntry } from "../../config/sessions.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; import {
resolveAgentDeliveryPlan,
resolveAgentOutboundTarget,
} from "../../infra/outbound/agent-delivery.js"; import { resolveMessageChannelSelection } from "../../infra/outbound/channel-selection.js"; import { deliverOutboundPayloads } from "../../infra/outbound/deliver.js"; import { buildOutboundResultEnvelope } from "../../infra/outbound/envelope.js"; import {
createOutboundPayloadPlan,
formatOutboundPayloadLog,
type NormalizedOutboundPayload,
projectOutboundPayloadPlanForJson,
projectOutboundPayloadPlanForOutbound,
} from "../../infra/outbound/payloads.js"; import type { OutboundSessionContext } from "../../infra/outbound/session-context.js"; import type { RuntimeEnv } from "../../runtime.js"; import { isInternalMessageChannel } from "../../utils/message-channel.js"; import { isNestedAgentLane } from "../lanes.js"; import type { AgentCommandOpts } from "./types.js";
type RunResult = Awaited<ReturnType<(typeofimport("../pi-embedded.js"))["runEmbeddedPiAgent"]>>;
const NESTED_LOG_PREFIX = "[agent:nested]";
function formatNestedLogPrefix(opts: AgentCommandOpts, sessionKey?: string): string { const parts = [NESTED_LOG_PREFIX]; const session = sessionKey ?? opts.sessionKey ?? opts.sessionId; if (session) {
parts.push(`session=${session}`);
} if (opts.runId) {
parts.push(`run=${opts.runId}`);
} const channel = opts.messageChannel ?? opts.channel; if (channel) {
parts.push(`channel=${channel}`);
} if (opts.to) {
parts.push(`to=${opts.to}`);
} if (opts.accountId) {
parts.push(`account=${opts.accountId}`);
} return parts.join(" ");
}
function logNestedOutput(
runtime: RuntimeEnv,
opts: AgentCommandOpts,
output: string,
sessionKey?: string,
) { const prefix = formatNestedLogPrefix(opts, sessionKey); for (const line of output.split(/\r?\n/)) { if (!line) { continue;
}
runtime.log(`${prefix} ${line}`);
}
}
if (deliver) { if (isInternalMessageChannel(deliveryChannel)) { const err = new Error( "delivery channel is required: pass --channel/--reply-channel or use a main session with a previous channel",
); if (!bestEffortDeliver) { throw err;
}
logDeliveryError(err);
} elseif (!isDeliveryChannelKnown) { const err = new Error(`Unknown channel: ${deliveryChannel}`); if (!bestEffortDeliver) { throw err;
}
logDeliveryError(err);
} elseif (resolvedTarget && !resolvedTarget.ok) { if (!bestEffortDeliver) { throw resolvedTarget.error;
}
logDeliveryError(resolvedTarget.error);
}
}
const normalizedReplyPayloads = normalizeAgentCommandReplyPayloads({
cfg,
opts,
outboundSession,
payloads,
result,
deliveryChannel,
accountId: resolvedAccountId,
applyChannelTransforms: deliver,
}); // Auto-reply-style media-path normalization must also run for the CLI // `--deliver` path. Without it, relative `MEDIA:./out/photo.png` tokens // reach the outbound loader unresolved and `assertLocalMediaAllowed` fails // with "Local media path is not under an allowed directory". Mirrors the // normalizer wiring in `src/auto-reply/reply/agent-runner.ts`. const mediaNormalizedReplyPayloads =
deliver && !isInternalMessageChannel(deliveryChannel)
? await normalizeReplyMediaPathsForDelivery({
cfg,
payloads: normalizedReplyPayloads,
sessionKey: effectiveSessionKey,
outboundSession,
deliveryChannel,
accountId: resolvedAccountId,
})
: normalizedReplyPayloads; const outboundPayloadPlan = createOutboundPayloadPlan(mediaNormalizedReplyPayloads); const normalizedPayloads = projectOutboundPayloadPlanForJson(outboundPayloadPlan); if (opts.json) {
runtime.log(
JSON.stringify(
buildOutboundResultEnvelope({
payloads: normalizedPayloads,
meta: result.meta,
}), null, 2,
),
); if (!deliver) { return { payloads: normalizedPayloads, meta: result.meta };
}
}
if (!payloads || payloads.length === 0) {
runtime.log("No reply from agent."); return { payloads: [], meta: result.meta };
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.