Download src/agents/command/run-context.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/agents/command/run-context.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/agents/command/run-context.ts
-
curl -L -o run-context.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/agents/command/run-context.ts
2 kB
| /** | |
| * Resolves channel/account/thread run context for agent command execution. | |
| */ | |
| import { stringifyRouteThreadId } from "../../plugin-sdk/channel-route.js"; | |
| import { normalizeOptionalAccountId } from "../../routing/account-id.js"; | |
| import { resolveMessageChannel } from "../../utils/message-channel.js"; | |
| import type { AgentCommandOpts, AgentRunContext } from "./types.js"; | |
| /** Merges explicit run context with command routing options. */ | |
| export function resolveAgentRunContext(opts: AgentCommandOpts): AgentRunContext { | |
| const merged: AgentRunContext = opts.runContext ? { ...opts.runContext } : {}; | |
| const normalizedChannel = resolveMessageChannel( | |
| merged.messageChannel ?? opts.messageChannel, | |
| opts.replyChannel ?? opts.channel, | |
| ); | |
| if (normalizedChannel) { | |
| merged.messageChannel = normalizedChannel; | |
| } | |
| const normalizedAccountId = normalizeOptionalAccountId(merged.accountId ?? opts.accountId); | |
| if (normalizedAccountId) { | |
| merged.accountId = normalizedAccountId; | |
| } | |
| const groupId = (merged.groupId ?? opts.groupId)?.toString().trim(); | |
| if (groupId) { | |
| merged.groupId = groupId; | |
| } | |
| const groupChannel = (merged.groupChannel ?? opts.groupChannel)?.toString().trim(); | |
| if (groupChannel) { | |
| merged.groupChannel = groupChannel; | |
| } | |
| const groupSpace = (merged.groupSpace ?? opts.groupSpace)?.toString().trim(); | |
| if (groupSpace) { | |
| merged.groupSpace = groupSpace; | |
| } | |
| if ( | |
| merged.currentThreadTs == null && | |
| opts.threadId != null && | |
| opts.threadId !== "" && | |
| opts.threadId !== null | |
| ) { | |
| const threadId = stringifyRouteThreadId(opts.threadId); | |
| if (threadId) { | |
| merged.currentThreadTs = threadId; | |
| } | |
| } | |
| // Populate currentChannelId from the outbound target so channel threading | |
| // adapters can detect same-conversation auto-threading. | |
| if (!merged.currentChannelId && opts.to) { | |
| const trimmedTo = opts.to.trim(); | |
| if (trimmedTo) { | |
| merged.currentChannelId = trimmedTo; | |
| } | |
| } | |
| return merged; | |
| } | |