UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

70 lines (69 loc) • 2.78 kB
import "./registry-Cu3BYvNI.mjs"; import { t as normalizeAnyChannelId } from "./registry-normalize-BnQO61Jh.mjs"; import { n as getLoadedChannelPlugin } from "./registry-B56V4gqI.mjs"; import "./plugins-CBMHLsl7.mjs"; import { r as resolveOutboundChannelPlugin } from "./channel-resolution-ojzsCEFE.mjs"; //#region src/infra/outbound/delivery-format-prompt.ts const DELIVERY_FORMAT_LEAD = { reply: "The JSON below is generated by OpenClaw. Your visible output for this turn is delivered to this channel; follow its response_format.", message_tool: "The JSON below is generated by OpenClaw. Text you send to this channel with the message tool is rendered by it; follow its response_format." }; /** Renders the delivering channel's formatting contract; only delivered runs bootstrap. */ function buildDeliveryFormatPrompt(params) { if (!params.channel) return; const plugin = params.allowBootstrap ? resolveOutboundChannelPlugin({ channel: params.channel, cfg: params.cfg, agentId: params.agentId, allowBootstrap: true }) : getLoadedChannelPlugin(normalizeAnyChannelId(params.channel) ?? params.channel); const responseFormat = plugin?.agentPrompt?.inboundFormattingHints?.({ cfg: params.cfg, accountId: params.accountId?.trim() || void 0 }); if (!plugin || !responseFormat) return; const payload = { schema: "openclaw.delivery_format.v1", channel: plugin.id, response_format: responseFormat }; return [ "### Delivery Format", DELIVERY_FORMAT_LEAD[params.via ?? "reply"], "", "```json", JSON.stringify(payload, null, 2), "```", "" ].join("\n"); } /** * Renders the contract for message-tool sends from a run without a reply route. * Callers add it only once the run's final tool surface includes `message`. */ async function resolveMessageToolDeliveryFormatPrompt(params) { const channel = params.channel ?? await import("./channel-selection.runtime.js").then(({ resolveMessageChannelSelection }) => resolveMessageChannelSelection({ cfg: params.cfg, agentId: params.agentId })).then((selection) => selection.channel).catch(() => void 0); const render = (accountId) => buildDeliveryFormatPrompt({ cfg: params.cfg, channel, accountId, via: "message_tool", agentId: params.agentId, allowBootstrap: true }); if (params.accountId?.trim() || !channel) return render(params.accountId); const plugin = resolveOutboundChannelPlugin({ channel, cfg: params.cfg, agentId: params.agentId, allowBootstrap: true }); const prompts = new Set((plugin?.config.listAccountIds(params.cfg) ?? []).map((accountId) => render(accountId))); prompts.add(render(void 0)); return prompts.size === 1 ? [...prompts][0] : void 0; } //#endregion export { resolveMessageToolDeliveryFormatPrompt as n, buildDeliveryFormatPrompt as t };