mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 14:00:43 +00:00
* refactor: consume acpx runtime library * refactor: remove duplicated acpx runtime files * fix: update acpx runtime dependency * fix: preserve acp runtime error codes * fix: migrate legacy acpx session files * fix: update acpx runtime dependency * fix: import Dirent from node fs * ACPX: repin shared runtime engine * ACPX: repin runtime semantics fixes * ACPX: repin runtime contract cleanup * Extensions: repin ACPX after layout refactor * ACPX: drop legacy session migration * ACPX: drop direct ACP SDK dependency * Discord ACP: stop duplicate direct fallback replies * ACP: rename delivered text visibility hook * ACPX: pin extension to 0.5.0 * Deps: drop stale ACPX build-script allowlist * ACPX: add local development guidance * ACPX: document temporary pnpm exception flow * SDK: preserve legacy ACP visibility hook * ACP: keep reset commands on local path * ACP: make in-place reset start fresh session * ACP: recover broken bindings on fresh reset * ACP: defer fresh reset marker until close succeeds * ACP: reset bound sessions fresh again * Discord: ensure ACP bindings before /new * ACP: recover missing persistent sessions
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
export const ACP_ERROR_CODES = [
|
|
"ACP_BACKEND_MISSING",
|
|
"ACP_BACKEND_UNAVAILABLE",
|
|
"ACP_BACKEND_UNSUPPORTED_CONTROL",
|
|
"ACP_DISPATCH_DISABLED",
|
|
"ACP_INVALID_RUNTIME_OPTION",
|
|
"ACP_SESSION_INIT_FAILED",
|
|
"ACP_TURN_FAILED",
|
|
] as const;
|
|
|
|
export type AcpRuntimeErrorCode = (typeof ACP_ERROR_CODES)[number];
|
|
const ACP_ERROR_CODE_SET = new Set<AcpRuntimeErrorCode>(ACP_ERROR_CODES);
|
|
|
|
export class AcpRuntimeError extends Error {
|
|
readonly code: AcpRuntimeErrorCode;
|
|
override readonly cause?: unknown;
|
|
|
|
constructor(code: AcpRuntimeErrorCode, message: string, options?: { cause?: unknown }) {
|
|
super(message);
|
|
this.name = "AcpRuntimeError";
|
|
this.code = code;
|
|
this.cause = options?.cause;
|
|
}
|
|
}
|
|
|
|
function getForeignAcpRuntimeError(value: unknown): {
|
|
code: AcpRuntimeErrorCode;
|
|
message: string;
|
|
} | null {
|
|
if (!(value instanceof Error)) {
|
|
return null;
|
|
}
|
|
const code = (value as { code?: unknown }).code;
|
|
if (typeof code !== "string" || !ACP_ERROR_CODE_SET.has(code as AcpRuntimeErrorCode)) {
|
|
return null;
|
|
}
|
|
return {
|
|
code: code as AcpRuntimeErrorCode,
|
|
message: value.message,
|
|
};
|
|
}
|
|
|
|
export function isAcpRuntimeError(value: unknown): value is AcpRuntimeError {
|
|
return value instanceof AcpRuntimeError || getForeignAcpRuntimeError(value) !== null;
|
|
}
|
|
|
|
export function toAcpRuntimeError(params: {
|
|
error: unknown;
|
|
fallbackCode: AcpRuntimeErrorCode;
|
|
fallbackMessage: string;
|
|
}): AcpRuntimeError {
|
|
if (params.error instanceof AcpRuntimeError) {
|
|
return params.error;
|
|
}
|
|
const foreignAcpRuntimeError = getForeignAcpRuntimeError(params.error);
|
|
if (foreignAcpRuntimeError) {
|
|
return new AcpRuntimeError(foreignAcpRuntimeError.code, foreignAcpRuntimeError.message, {
|
|
cause: params.error,
|
|
});
|
|
}
|
|
if (params.error instanceof Error) {
|
|
return new AcpRuntimeError(params.fallbackCode, params.error.message, {
|
|
cause: params.error,
|
|
});
|
|
}
|
|
return new AcpRuntimeError(params.fallbackCode, params.fallbackMessage, {
|
|
cause: params.error,
|
|
});
|
|
}
|
|
|
|
export async function withAcpRuntimeErrorBoundary<T>(params: {
|
|
run: () => Promise<T>;
|
|
fallbackCode: AcpRuntimeErrorCode;
|
|
fallbackMessage: string;
|
|
}): Promise<T> {
|
|
try {
|
|
return await params.run();
|
|
} catch (error) {
|
|
throw toAcpRuntimeError({
|
|
error,
|
|
fallbackCode: params.fallbackCode,
|
|
fallbackMessage: params.fallbackMessage,
|
|
});
|
|
}
|
|
}
|