UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

64 lines (63 loc) 3.63 kB
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { a as normalizeChannelId, t as getChannelPlugin } from "./registry-Cz6cv4VC.js"; import "./plugins-Cozj1Enf.js"; import { t as getSessionBindingService } from "./session-binding-service-DTXs8JDw.js"; import { t as formatRunLabel } from "./subagents-utils-ChHH_ZbO.js"; import { n as buildSubagentRunReadIndex } from "./subagent-registry-read-DeFf_9Nz.js"; import { t as buildSubagentRunView } from "./subagent-run-view-BqhTqM1D.js"; import { n as commandReply } from "./command-gates-B4tlStPI.js"; import "./shared-Cn64ilNP.js"; import { n as resolveCommandSurfaceChannel, t as resolveChannelAccountId } from "./channel-context-DRwyIHwz.js"; //#region src/auto-reply/reply/commands-subagents/action-agents.ts function formatConversationBindingText(params) { return `binding:${params.conversationId}`; } function supportsConversationBindings(channel) { const channelId = normalizeChannelId(channel); if (!channelId) return false; return getChannelPlugin(channelId)?.conversationBindings?.supportsCurrentConversationBinding === true; } function handleSubagentsAgentsAction(ctx) { const { params, requesterKey, runs } = ctx; const readIndex = buildSubagentRunReadIndex(); const channel = resolveCommandSurfaceChannel(params); const accountId = resolveChannelAccountId(params); const currentConversationBindingsSupported = supportsConversationBindings(channel); const bindingService = getSessionBindingService(); const bindingsBySession = /* @__PURE__ */ new Map(); const resolveSessionBindings = (sessionKey) => { const cached = bindingsBySession.get(sessionKey); if (cached) return cached; const resolved = bindingService.listBySession(sessionKey).filter((entry) => entry.status === "active" && entry.conversation.channel === channel && entry.conversation.accountId === accountId); bindingsBySession.set(sessionKey, resolved); return resolved; }; const { latest, active, recent } = buildSubagentRunView({ runs, recentMinutes: 30, countPendingDescendantRuns: (sessionKey) => readIndex.countPendingDescendantRuns(sessionKey) }); const indexByChildSessionKey = new Map([...active, ...recent].map((entry, idx) => [entry.childSessionKey, idx + 1])); const activeRuns = new Set(active); const visibleRuns = latest.filter((entry) => activeRuns.has(entry) || resolveSessionBindings(entry.childSessionKey).length > 0); const lines = ["agents:", "-----"]; if (visibleRuns.length === 0) lines.push("(none)"); else for (const entry of visibleRuns) { const binding = resolveSessionBindings(entry.childSessionKey)[0]; const bindingText = binding ? formatConversationBindingText({ conversationId: binding.conversation.conversationId }) : currentConversationBindingsSupported ? "unbound" : "bindings unavailable"; const resolvedIndex = indexByChildSessionKey.get(entry.childSessionKey); const prefix = resolvedIndex ? `${resolvedIndex}.` : "-"; lines.push(`${prefix} ${formatRunLabel(entry)} (${bindingText})`); } const requesterBindings = resolveSessionBindings(requesterKey).filter((entry) => entry.targetKind === "session"); if (requesterBindings.length > 0) { lines.push("", "acp/session bindings:", "-----"); for (const binding of requesterBindings) { const label = normalizeOptionalString(binding.metadata?.label) ?? binding.targetSessionKey; lines.push(`- ${label} (${formatConversationBindingText({ conversationId: binding.conversation.conversationId })}, session:${binding.targetSessionKey})`); } } return commandReply(lines.join("\n")); } //#endregion export { handleSubagentsAgentsAction };