mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 12:00:43 +00:00
* docs: add ACP persistent binding experiment plan * docs: align ACP persistent binding spec to channel-local config * docs: scope Telegram ACP bindings to forum topics only * docs: lock bound /new and /reset behavior to in-place ACP reset * ACP: add persistent discord/telegram conversation bindings * ACP: fix persistent binding reuse and discord thread parent context * docs: document channel-specific persistent ACP bindings * ACP: split persistent bindings and share conversation id helpers * ACP: defer configured binding init until preflight passes * ACP: fix discord thread parent fallback and explicit disable inheritance * ACP: keep bound /new and /reset in-place * ACP: honor configured bindings in native command flows * ACP: avoid configured fallback after runtime bind failure * docs: refine ACP bindings experiment config examples * acp: cut over to typed top-level persistent bindings * ACP bindings: harden reset recovery and native command auth * Docs: add ACP bound command auth proposal * Tests: normalize i18n registry zh-CN assertion encoding * ACP bindings: address review findings for reset and fallback routing * ACP reset: gate hooks on success and preserve /new arguments * ACP bindings: fix auth and binding-priority review findings * Telegram ACP: gate ensure on auth and accepted messages * ACP bindings: fix session-key precedence and unavailable handling * ACP reset/native commands: honor fallback targets and abort on bootstrap failure * Config schema: validate ACP binding channel and Telegram topic IDs * Discord ACP: apply configured DM bindings to native commands * ACP reset tails: dispatch through ACP after command handling * ACP tails/native reset auth: fix target dispatch and restore full auth * ACP reset detection: fallback to active ACP keys for DM contexts * Tests: type runTurn mock input in ACP dispatch test * ACP: dedup binding route bootstrap and reset target resolution * reply: align ACP reset hooks with bound session key * docs: replace personal discord ids with placeholders * fix: add changelog entry for ACP persistent bindings (#34873) (thanks @dutifulbob) --------- Co-authored-by: Onur <2453968+osolmaz@users.noreply.github.com>
106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import type { SessionBindingRecord } from "../infra/outbound/session-binding-service.js";
|
|
import { sanitizeAgentId } from "../routing/session-key.js";
|
|
import type { AcpRuntimeSessionMode } from "./runtime/types.js";
|
|
|
|
export type ConfiguredAcpBindingChannel = "discord" | "telegram";
|
|
|
|
export type ConfiguredAcpBindingSpec = {
|
|
channel: ConfiguredAcpBindingChannel;
|
|
accountId: string;
|
|
conversationId: string;
|
|
parentConversationId?: string;
|
|
/** Owning OpenClaw agent id (used for session identity/storage). */
|
|
agentId: string;
|
|
/** ACP harness agent id override (falls back to agentId when omitted). */
|
|
acpAgentId?: string;
|
|
mode: AcpRuntimeSessionMode;
|
|
cwd?: string;
|
|
backend?: string;
|
|
label?: string;
|
|
};
|
|
|
|
export type ResolvedConfiguredAcpBinding = {
|
|
spec: ConfiguredAcpBindingSpec;
|
|
record: SessionBindingRecord;
|
|
};
|
|
|
|
export type AcpBindingConfigShape = {
|
|
mode?: string;
|
|
cwd?: string;
|
|
backend?: string;
|
|
label?: string;
|
|
};
|
|
|
|
export function normalizeText(value: unknown): string | undefined {
|
|
if (typeof value !== "string") {
|
|
return undefined;
|
|
}
|
|
const trimmed = value.trim();
|
|
return trimmed || undefined;
|
|
}
|
|
|
|
export function normalizeMode(value: unknown): AcpRuntimeSessionMode {
|
|
const raw = normalizeText(value)?.toLowerCase();
|
|
return raw === "oneshot" ? "oneshot" : "persistent";
|
|
}
|
|
|
|
export function normalizeBindingConfig(raw: unknown): AcpBindingConfigShape {
|
|
if (!raw || typeof raw !== "object") {
|
|
return {};
|
|
}
|
|
const shape = raw as AcpBindingConfigShape;
|
|
const mode = normalizeText(shape.mode);
|
|
return {
|
|
mode: mode ? normalizeMode(mode) : undefined,
|
|
cwd: normalizeText(shape.cwd),
|
|
backend: normalizeText(shape.backend),
|
|
label: normalizeText(shape.label),
|
|
};
|
|
}
|
|
|
|
function buildBindingHash(params: {
|
|
channel: ConfiguredAcpBindingChannel;
|
|
accountId: string;
|
|
conversationId: string;
|
|
}): string {
|
|
return createHash("sha256")
|
|
.update(`${params.channel}:${params.accountId}:${params.conversationId}`)
|
|
.digest("hex")
|
|
.slice(0, 16);
|
|
}
|
|
|
|
export function buildConfiguredAcpSessionKey(spec: ConfiguredAcpBindingSpec): string {
|
|
const hash = buildBindingHash({
|
|
channel: spec.channel,
|
|
accountId: spec.accountId,
|
|
conversationId: spec.conversationId,
|
|
});
|
|
return `agent:${sanitizeAgentId(spec.agentId)}:acp:binding:${spec.channel}:${spec.accountId}:${hash}`;
|
|
}
|
|
|
|
export function toConfiguredAcpBindingRecord(spec: ConfiguredAcpBindingSpec): SessionBindingRecord {
|
|
return {
|
|
bindingId: `config:acp:${spec.channel}:${spec.accountId}:${spec.conversationId}`,
|
|
targetSessionKey: buildConfiguredAcpSessionKey(spec),
|
|
targetKind: "session",
|
|
conversation: {
|
|
channel: spec.channel,
|
|
accountId: spec.accountId,
|
|
conversationId: spec.conversationId,
|
|
parentConversationId: spec.parentConversationId,
|
|
},
|
|
status: "active",
|
|
boundAt: 0,
|
|
metadata: {
|
|
source: "config",
|
|
mode: spec.mode,
|
|
agentId: spec.agentId,
|
|
...(spec.acpAgentId ? { acpAgentId: spec.acpAgentId } : {}),
|
|
label: spec.label,
|
|
...(spec.backend ? { backend: spec.backend } : {}),
|
|
...(spec.cwd ? { cwd: spec.cwd } : {}),
|
|
},
|
|
};
|
|
}
|