mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
refactor(ui): reuse canonical UUID generation (#128753)
This commit is contained in:
committed by
GitHub
parent
b8d6e799a3
commit
3cf23294a5
@@ -11,6 +11,7 @@ import type { ApplicationContext } from "../app/context.ts";
|
||||
import { hasOperatorAdminAccess } from "../app/operator-access.ts";
|
||||
import { t } from "../i18n/index.ts";
|
||||
import { formatUiError, formatUiExternalText } from "../lib/format-error.ts";
|
||||
import { generateUUID } from "../lib/uuid.ts";
|
||||
import { OpenClawLightDomElement } from "../lit/openclaw-element.ts";
|
||||
import { SubscriptionsController } from "../lit/subscriptions-controller.ts";
|
||||
import "../styles/onboarding-memory-import.css";
|
||||
@@ -27,15 +28,6 @@ function toErrorMessage(error: unknown): string {
|
||||
return formatUiError(error, t("onboarding.memoryImport.unknownError"));
|
||||
}
|
||||
|
||||
function createIdempotencyKey(): string {
|
||||
if (typeof globalThis.crypto.randomUUID === "function") {
|
||||
return globalThis.crypto.randomUUID();
|
||||
}
|
||||
return [...globalThis.crypto.getRandomValues(new Uint32Array(4))]
|
||||
.map((value) => value.toString(16).padStart(8, "0"))
|
||||
.join("");
|
||||
}
|
||||
|
||||
function plannedItems(provider: MemoryMigrationProviderPlan) {
|
||||
return provider.items.filter((item) => item.status === "planned");
|
||||
}
|
||||
@@ -244,7 +236,7 @@ class OnboardingMemoryImport extends OpenClawLightDomElement {
|
||||
const result = await client.request<MigrationsMemoryApplyResult>(
|
||||
"migrations.memory.apply",
|
||||
{
|
||||
idempotencyKey: createIdempotencyKey(),
|
||||
idempotencyKey: generateUUID(),
|
||||
agentId,
|
||||
providerId: provider.providerId,
|
||||
planFingerprint,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ApplicationGateway } from "../../app/context.ts";
|
||||
import { generateUUID } from "../../lib/uuid.ts";
|
||||
import { getSafeLocalStorage } from "../../local-storage.ts";
|
||||
|
||||
const CUSTODIAN_SESSION_STORAGE_KEY = "openclaw.custodian.session.v1";
|
||||
@@ -8,13 +9,7 @@ function isStoredCustodianSessionId(value: string | null): value is string {
|
||||
}
|
||||
|
||||
export function createCustodianSessionId(): string {
|
||||
if (typeof crypto.randomUUID === "function") {
|
||||
return `control-ui-onboarding-${crypto.randomUUID()}`;
|
||||
}
|
||||
const suffix = [...crypto.getRandomValues(new Uint32Array(4))]
|
||||
.map((value) => value.toString(16).padStart(8, "0"))
|
||||
.join("");
|
||||
return `control-ui-onboarding-${suffix}`;
|
||||
return `control-ui-onboarding-${generateUUID()}`;
|
||||
}
|
||||
|
||||
export function persistCustodianSessionId(sessionId: string): void {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { t } from "../../i18n/index.ts";
|
||||
import { listSelectableAgents } from "../../lib/agents/display.ts";
|
||||
import { formatUiError } from "../../lib/format-error.ts";
|
||||
import { isGatewayMethodAdvertised } from "../../lib/gateway-methods.ts";
|
||||
import { generateUUID } from "../../lib/uuid.ts";
|
||||
import { OpenClawLightDomElement } from "../../lit/openclaw-element.ts";
|
||||
import { SubscriptionsController } from "../../lit/subscriptions-controller.ts";
|
||||
import {
|
||||
@@ -41,15 +42,6 @@ function toErrorMessage(error: unknown): string {
|
||||
return formatUiError(error, "request failed");
|
||||
}
|
||||
|
||||
function createIdempotencyKey(): string {
|
||||
if (typeof globalThis.crypto.randomUUID === "function") {
|
||||
return globalThis.crypto.randomUUID();
|
||||
}
|
||||
return [...globalThis.crypto.getRandomValues(new Uint32Array(4))]
|
||||
.map((value) => value.toString(16).padStart(8, "0"))
|
||||
.join("");
|
||||
}
|
||||
|
||||
export class MemoryImportPage extends OpenClawLightDomElement {
|
||||
@consume({ context: applicationContext, subscribe: true })
|
||||
private context!: ApplicationContext;
|
||||
@@ -275,7 +267,7 @@ export class MemoryImportPage extends OpenClawLightDomElement {
|
||||
planFingerprint,
|
||||
itemIds: [...itemIds],
|
||||
overwrite: this.replaceExisting,
|
||||
idempotencyKey: createIdempotencyKey(),
|
||||
idempotencyKey: generateUUID(),
|
||||
attempted: false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user