1+ /** Shared ACP manager normalization, resolution, and error helpers. */
12import { ACP_ERROR_CODES , AcpRuntimeError } from "@openclaw/acp-core/runtime/errors" ;
23import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce" ;
34import {
@@ -19,13 +20,15 @@ export function resolveAcpAgentFromSessionKey(sessionKey: string, fallback = "ma
1920 return normalizeAgentId ( parsed ?. agentId ?? fallback ) ;
2021}
2122
23+ /** Builds the stale-session error shown when ACP metadata is missing. */
2224export function resolveMissingMetaError ( sessionKey : string ) : AcpRuntimeError {
2325 return new AcpRuntimeError (
2426 "ACP_SESSION_INIT_FAILED" ,
2527 `ACP metadata is missing for ${ sessionKey } . Recreate this ACP session with /acp spawn and rebind the thread.` ,
2628 ) ;
2729}
2830
31+ /** Converts a session resolution union into the runtime error callers should throw. */
2932export function resolveAcpSessionResolutionError (
3033 resolution : AcpSessionResolution ,
3134) : AcpRuntimeError | null {
@@ -41,6 +44,7 @@ export function resolveAcpSessionResolutionError(
4144 ) ;
4245}
4346
47+ /** Returns ready ACP metadata or throws the matching resolution error. */
4448export function requireReadySessionMeta ( resolution : AcpSessionResolution ) : SessionAcpMeta {
4549 if ( resolution . kind === "ready" ) {
4650 return resolution . meta ;
@@ -52,6 +56,7 @@ function normalizeSessionKey(sessionKey: string): string {
5256 return sessionKey . trim ( ) ;
5357}
5458
59+ /** Canonicalizes aliases and main-session keys before ACP metadata lookup. */
5560export function canonicalizeAcpSessionKey ( params : {
5661 cfg : OpenClawConfig ;
5762 sessionKey : string ;
@@ -79,10 +84,12 @@ export function canonicalizeAcpSessionKey(params: {
7984 return lowered ;
8085}
8186
87+ /** Normalizes session keys for process-local actor maps. */
8288export function normalizeActorKey ( sessionKey : string ) : string {
8389 return normalizeLowercaseStringOrEmpty ( sessionKey ) ;
8490}
8591
92+ /** Restricts runtime-provided error codes to the ACP error-code enum. */
8693export function normalizeAcpErrorCode ( code : string | undefined ) : AcpRuntimeError [ "code" ] {
8794 if ( ! code ) {
8895 return "ACP_TURN_FAILED" ;
0 commit comments