mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:34:32 +00:00
fix(sandbox): preserve array order in config hashing
This commit is contained in:
@@ -19,24 +19,12 @@ type SandboxBrowserHashInput = {
|
||||
agentWorkspaceDir: string;
|
||||
};
|
||||
|
||||
function isPrimitive(value: unknown): value is string | number | boolean | bigint | symbol | null {
|
||||
return value === null || (typeof value !== "object" && typeof value !== "function");
|
||||
}
|
||||
function normalizeForHash(value: unknown): unknown {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
const normalized = value
|
||||
.map(normalizeForHash)
|
||||
.filter((item): item is unknown => item !== undefined);
|
||||
const primitives = normalized.filter(isPrimitive);
|
||||
if (primitives.length === normalized.length) {
|
||||
return [...primitives].toSorted((a, b) =>
|
||||
primitiveToString(a).localeCompare(primitiveToString(b)),
|
||||
);
|
||||
}
|
||||
return normalized;
|
||||
return value.map(normalizeForHash).filter((item): item is unknown => item !== undefined);
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
const entries = Object.entries(value).toSorted(([a], [b]) => a.localeCompare(b));
|
||||
@@ -52,22 +40,6 @@ function normalizeForHash(value: unknown): unknown {
|
||||
return value;
|
||||
}
|
||||
|
||||
function primitiveToString(value: unknown): string {
|
||||
if (value === null) {
|
||||
return "null";
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "number") {
|
||||
return String(value);
|
||||
}
|
||||
if (typeof value === "boolean") {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
|
||||
export function computeSandboxConfigHash(input: SandboxHashInput): string {
|
||||
return computeHash(input);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user