|
1 | 1 | import { randomUUID } from "node:crypto"; |
2 | 2 | import { resolveTimerTimeoutMs } from "@openclaw/normalization-core/number-coercion"; |
3 | 3 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
4 | | -import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload"; |
5 | 4 | import { |
6 | 5 | GATEWAY_CLIENT_MODES, |
7 | 6 | GATEWAY_CLIENT_NAMES, |
@@ -106,6 +105,9 @@ const AGENT_CLI_SIGNAL_EXIT_CODES: Record<AgentCliSignal, number> = {
|
106 | 105 | |
107 | 106 | let embeddedAgentCommandPromise: Promise<EmbeddedAgentCommandModule["agentCommand"]> | undefined; |
108 | 107 | let agentSessionModulePromise: Promise<AgentSessionModule> | undefined; |
| 108 | +let replyPayloadModulePromise: |
| 109 | +| Promise<typeof import("openclaw/plugin-sdk/reply-payload")> |
| 110 | +| undefined; |
109 | 111 | const defaultAgentSessionModuleLoader: AgentSessionModuleLoader = () => |
110 | 112 | import("./agent/session.js"); |
111 | 113 | let agentSessionModuleLoader: AgentSessionModuleLoader = defaultAgentSessionModuleLoader; |
@@ -125,10 +127,16 @@ function loadAgentSessionModule(): Promise<AgentSessionModule> {
|
125 | 127 | return agentSessionModulePromise; |
126 | 128 | } |
127 | 129 | |
| 130 | +function loadReplyPayloadModule() { |
| 131 | +replyPayloadModulePromise ??= import("openclaw/plugin-sdk/reply-payload"); |
| 132 | +return replyPayloadModulePromise; |
| 133 | +} |
| 134 | + |
128 | 135 | export const agentViaGatewayTesting = { |
129 | 136 | resetLazyImportsForTests(): void { |
130 | 137 | embeddedAgentCommandPromise = undefined; |
131 | 138 | agentSessionModulePromise = undefined; |
| 139 | +replyPayloadModulePromise = undefined; |
132 | 140 | agentSessionModuleLoader = defaultAgentSessionModuleLoader; |
133 | 141 | }, |
134 | 142 | setAgentSessionModuleLoaderForTests(loader: AgentSessionModuleLoader): void { |
@@ -173,11 +181,12 @@ function getGatewayDispatchConfig(): OpenClawConfig {
|
173 | 181 | return getRuntimeConfig({ skipPluginValidation: true, pin: false }); |
174 | 182 | } |
175 | 183 | |
176 | | -function formatPayloadForLog(payload: { |
| 184 | +async function formatPayloadForLog(payload: { |
177 | 185 | text?: string; |
178 | 186 | mediaUrls?: string[]; |
179 | 187 | mediaUrl?: string | null; |
180 | 188 | }) { |
| 189 | +const { resolveSendableOutboundReplyParts } = await loadReplyPayloadModule(); |
181 | 190 | const parts = resolveSendableOutboundReplyParts({ |
182 | 191 | text: payload.text, |
183 | 192 | mediaUrls: payload.mediaUrls, |
@@ -724,7 +733,7 @@ async function agentViaGatewayCommand(
|
724 | 733 | } |
725 | 734 | |
726 | 735 | for (const payload of payloads) { |
727 | | -const out = formatPayloadForLog(payload); |
| 736 | +const out = await formatPayloadForLog(payload); |
728 | 737 | if (out) { |
729 | 738 | runtime.log(out); |
730 | 739 | } |
|