mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 12:00:44 +00:00
refactor: share agent binding formatter
This commit is contained in:
19
src/commands/agents.binding-format.ts
Normal file
19
src/commands/agents.binding-format.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { AgentRouteBinding } from "../config/types.js";
|
||||
|
||||
export function describeBinding(binding: AgentRouteBinding): string {
|
||||
const match = binding.match;
|
||||
const parts = [match.channel];
|
||||
if (match.accountId) {
|
||||
parts.push(`accountId=${match.accountId}`);
|
||||
}
|
||||
if (match.peer) {
|
||||
parts.push(`peer=${match.peer.kind}:${match.peer.id}`);
|
||||
}
|
||||
if (match.guildId) {
|
||||
parts.push(`guild=${match.guildId}`);
|
||||
}
|
||||
if (match.teamId) {
|
||||
parts.push(`team=${match.teamId}`);
|
||||
}
|
||||
return parts.join(" ");
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
import { normalizeStringEntries } from "../shared/string-normalization.js";
|
||||
import type { ChannelChoice } from "./onboard-types.js";
|
||||
|
||||
export { describeBinding } from "./agents.binding-format.js";
|
||||
|
||||
function bindingMatchKey(match: AgentRouteBinding["match"]) {
|
||||
const accountId = normalizeOptionalString(match.accountId) || DEFAULT_ACCOUNT_ID;
|
||||
const identityKey = bindingMatchIdentityKey(match);
|
||||
@@ -49,24 +51,6 @@ function canUpgradeBindingAccountScope(params: {
|
||||
);
|
||||
}
|
||||
|
||||
export function describeBinding(binding: AgentRouteBinding) {
|
||||
const match = binding.match;
|
||||
const parts = [match.channel];
|
||||
if (match.accountId) {
|
||||
parts.push(`accountId=${match.accountId}`);
|
||||
}
|
||||
if (match.peer) {
|
||||
parts.push(`peer=${match.peer.kind}:${match.peer.id}`);
|
||||
}
|
||||
if (match.guildId) {
|
||||
parts.push(`guild=${match.guildId}`);
|
||||
}
|
||||
if (match.teamId) {
|
||||
parts.push(`team=${match.teamId}`);
|
||||
}
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
export function applyAgentBindings(
|
||||
cfg: OpenClawConfig,
|
||||
bindings: AgentRouteBinding[],
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { AgentRouteBinding } from "../config/types.js";
|
||||
import { normalizeAgentId } from "../routing/session-key.js";
|
||||
import { type RuntimeEnv, writeRuntimeJson } from "../runtime.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { describeBinding } from "./agents.binding-format.js";
|
||||
import { requireValidConfig, requireValidConfigFileSnapshot } from "./agents.command-shared.js";
|
||||
|
||||
type AgentBindingsModule = typeof import("./agents.bindings.js");
|
||||
@@ -35,24 +36,6 @@ function loadAgentBindingsModule(): Promise<AgentBindingsModule> {
|
||||
return agentBindingsModulePromise;
|
||||
}
|
||||
|
||||
function describeBinding(binding: AgentRouteBinding): string {
|
||||
const match = binding.match;
|
||||
const parts = [match.channel];
|
||||
if (match.accountId) {
|
||||
parts.push(`accountId=${match.accountId}`);
|
||||
}
|
||||
if (match.peer) {
|
||||
parts.push(`peer=${match.peer.kind}:${match.peer.id}`);
|
||||
}
|
||||
if (match.guildId) {
|
||||
parts.push(`guild=${match.guildId}`);
|
||||
}
|
||||
if (match.teamId) {
|
||||
parts.push(`team=${match.teamId}`);
|
||||
}
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
function resolveAgentId(
|
||||
cfg: Awaited<ReturnType<typeof requireValidConfig>>,
|
||||
agentInput: string | undefined,
|
||||
|
||||
Reference in New Issue
Block a user