mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:34:32 +00:00
refactor: centralize acp session resolution guards
This commit is contained in:
@@ -2,6 +2,7 @@ import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { SessionAcpMeta } from "../../config/sessions/types.js";
|
||||
import { normalizeAgentId, parseAgentSessionKey } from "../../routing/session-key.js";
|
||||
import { ACP_ERROR_CODES, AcpRuntimeError } from "../runtime/errors.js";
|
||||
import type { AcpSessionResolution } from "./manager.types.js";
|
||||
|
||||
export function resolveAcpAgentFromSessionKey(sessionKey: string, fallback = "main"): string {
|
||||
const parsed = parseAgentSessionKey(sessionKey);
|
||||
@@ -15,6 +16,29 @@ export function resolveMissingMetaError(sessionKey: string): AcpRuntimeError {
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveAcpSessionResolutionError(
|
||||
resolution: AcpSessionResolution,
|
||||
): AcpRuntimeError | null {
|
||||
if (resolution.kind === "ready") {
|
||||
return null;
|
||||
}
|
||||
if (resolution.kind === "stale") {
|
||||
return resolution.error;
|
||||
}
|
||||
return new AcpRuntimeError(
|
||||
"ACP_SESSION_INIT_FAILED",
|
||||
`Session is not ACP-enabled: ${resolution.sessionKey}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function requireReadySessionMeta(resolution: AcpSessionResolution): SessionAcpMeta {
|
||||
const error = resolveAcpSessionResolutionError(resolution);
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
return resolution.meta;
|
||||
}
|
||||
|
||||
export function normalizeSessionKey(sessionKey: string): string {
|
||||
return sessionKey.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user