mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 18:00:22 +00:00
* ACPX: keep plugin-local runtime installs out of dist * Gateway: harden ACP startup and service PATH * ACP: reinitialize error-state configured bindings * ACP: classify pre-turn runtime failures as session init failures * Plugins: move configured ACP routing behind channel seams * Telegram tests: align startup probe assertions after rebase * Discord: harden ACP configured binding recovery * ACP: recover Discord bindings after stale runtime exits * ACPX: replace dead sessions during ensure * Discord: harden ACP binding recovery * Discord: fix review follow-ups * ACP bindings: load channel snapshots across workspaces * ACP bindings: cache snapshot channel plugin resolution * Experiments: add ACP pluginification holy grail plan * Experiments: rename ACP pluginification plan doc * Experiments: drop old ACP pluginification doc path * ACP: move configured bindings behind plugin services * Experiments: update bindings capability architecture plan * Bindings: isolate configured binding routing and targets * Discord tests: fix runtime env helper path * Tests: fix channel binding CI regressions * Tests: normalize ACP workspace assertion on Windows * Bindings: isolate configured binding registry * Bindings: finish configured binding cleanup * Bindings: finish generic cleanup * Bindings: align runtime approval callbacks * ACP: delete residual bindings barrel * Bindings: restore legacy compatibility * Revert "Bindings: restore legacy compatibility" This reverts commit ac2ed68fa2426ecc874d68278c71c71ad363fcfe. * Tests: drop ACP route legacy helper names * Discord/ACP: fix binding regressions --------- Co-authored-by: Onur <2453968+osolmaz@users.noreply.github.com>
156 lines
4.6 KiB
TypeScript
156 lines
4.6 KiB
TypeScript
import {
|
|
buildConfiguredAcpSessionKey,
|
|
normalizeBindingConfig,
|
|
normalizeMode,
|
|
normalizeText,
|
|
parseConfiguredAcpSessionKey,
|
|
toConfiguredAcpBindingRecord,
|
|
type ConfiguredAcpBindingSpec,
|
|
} from "../../acp/persistent-bindings.types.js";
|
|
import {
|
|
resolveAgentConfig,
|
|
resolveAgentWorkspaceDir,
|
|
resolveDefaultAgentId,
|
|
} from "../../agents/agent-scope.js";
|
|
import type { OpenClawConfig } from "../../config/config.js";
|
|
import type {
|
|
ConfiguredBindingRuleConfig,
|
|
ConfiguredBindingTargetFactory,
|
|
} from "./binding-types.js";
|
|
import type { ConfiguredBindingConsumer } from "./configured-binding-consumers.js";
|
|
import type { ChannelConfiguredBindingConversationRef } from "./types.adapters.js";
|
|
|
|
function resolveAgentRuntimeAcpDefaults(params: { cfg: OpenClawConfig; ownerAgentId: string }): {
|
|
acpAgentId?: string;
|
|
mode?: string;
|
|
cwd?: string;
|
|
backend?: string;
|
|
} {
|
|
const agent = params.cfg.agents?.list?.find(
|
|
(entry) => entry.id?.trim().toLowerCase() === params.ownerAgentId.toLowerCase(),
|
|
);
|
|
if (!agent || agent.runtime?.type !== "acp") {
|
|
return {};
|
|
}
|
|
return {
|
|
acpAgentId: normalizeText(agent.runtime.acp?.agent),
|
|
mode: normalizeText(agent.runtime.acp?.mode),
|
|
cwd: normalizeText(agent.runtime.acp?.cwd),
|
|
backend: normalizeText(agent.runtime.acp?.backend),
|
|
};
|
|
}
|
|
|
|
function resolveConfiguredBindingWorkspaceCwd(params: {
|
|
cfg: OpenClawConfig;
|
|
agentId: string;
|
|
}): string | undefined {
|
|
const explicitAgentWorkspace = normalizeText(
|
|
resolveAgentConfig(params.cfg, params.agentId)?.workspace,
|
|
);
|
|
if (explicitAgentWorkspace) {
|
|
return resolveAgentWorkspaceDir(params.cfg, params.agentId);
|
|
}
|
|
if (params.agentId === resolveDefaultAgentId(params.cfg)) {
|
|
const defaultWorkspace = normalizeText(params.cfg.agents?.defaults?.workspace);
|
|
if (defaultWorkspace) {
|
|
return resolveAgentWorkspaceDir(params.cfg, params.agentId);
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function buildConfiguredAcpSpec(params: {
|
|
channel: string;
|
|
accountId: string;
|
|
conversation: ChannelConfiguredBindingConversationRef;
|
|
agentId: string;
|
|
acpAgentId?: string;
|
|
mode: "persistent" | "oneshot";
|
|
cwd?: string;
|
|
backend?: string;
|
|
label?: string;
|
|
}): ConfiguredAcpBindingSpec {
|
|
return {
|
|
channel: params.channel as ConfiguredAcpBindingSpec["channel"],
|
|
accountId: params.accountId,
|
|
conversationId: params.conversation.conversationId,
|
|
parentConversationId: params.conversation.parentConversationId,
|
|
agentId: params.agentId,
|
|
acpAgentId: params.acpAgentId,
|
|
mode: params.mode,
|
|
cwd: params.cwd,
|
|
backend: params.backend,
|
|
label: params.label,
|
|
};
|
|
}
|
|
|
|
function buildAcpTargetFactory(params: {
|
|
cfg: OpenClawConfig;
|
|
binding: ConfiguredBindingRuleConfig;
|
|
channel: string;
|
|
agentId: string;
|
|
}): ConfiguredBindingTargetFactory | null {
|
|
if (params.binding.type !== "acp") {
|
|
return null;
|
|
}
|
|
const runtimeDefaults = resolveAgentRuntimeAcpDefaults({
|
|
cfg: params.cfg,
|
|
ownerAgentId: params.agentId,
|
|
});
|
|
const bindingOverrides = normalizeBindingConfig(params.binding.acp);
|
|
const mode = normalizeMode(bindingOverrides.mode ?? runtimeDefaults.mode);
|
|
const cwd =
|
|
bindingOverrides.cwd ??
|
|
runtimeDefaults.cwd ??
|
|
resolveConfiguredBindingWorkspaceCwd({
|
|
cfg: params.cfg,
|
|
agentId: params.agentId,
|
|
});
|
|
const backend = bindingOverrides.backend ?? runtimeDefaults.backend;
|
|
const label = bindingOverrides.label;
|
|
const acpAgentId = normalizeText(runtimeDefaults.acpAgentId);
|
|
|
|
return {
|
|
driverId: "acp",
|
|
materialize: ({ accountId, conversation }) => {
|
|
const spec = buildConfiguredAcpSpec({
|
|
channel: params.channel,
|
|
accountId,
|
|
conversation,
|
|
agentId: params.agentId,
|
|
acpAgentId,
|
|
mode,
|
|
cwd,
|
|
backend,
|
|
label,
|
|
});
|
|
const record = toConfiguredAcpBindingRecord(spec);
|
|
return {
|
|
record,
|
|
statefulTarget: {
|
|
kind: "stateful",
|
|
driverId: "acp",
|
|
sessionKey: buildConfiguredAcpSessionKey(spec),
|
|
agentId: params.agentId,
|
|
...(label ? { label } : {}),
|
|
},
|
|
};
|
|
},
|
|
};
|
|
}
|
|
|
|
export const acpConfiguredBindingConsumer: ConfiguredBindingConsumer = {
|
|
id: "acp",
|
|
supports: (binding) => binding.type === "acp",
|
|
buildTargetFactory: (params) =>
|
|
buildAcpTargetFactory({
|
|
cfg: params.cfg,
|
|
binding: params.binding,
|
|
channel: params.channel,
|
|
agentId: params.agentId,
|
|
}),
|
|
parseSessionKey: ({ sessionKey }) => parseConfiguredAcpSessionKey(sessionKey),
|
|
matchesSessionKey: ({ sessionKey, materializedTarget }) =>
|
|
materializedTarget.record.targetSessionKey === sessionKey,
|
|
};
|