2026-04-15 03:34:52 +08:00
|
|
|
import type { ConvexHttpClient } from "convex/browser";
|
|
|
|
|
import {
|
|
|
|
|
type CommandEnvelope,
|
|
|
|
|
type BridgeContext,
|
|
|
|
|
} from "@/lib/documents/bridge";
|
2026-04-15 20:01:12 +08:00
|
|
|
import {
|
|
|
|
|
recordBridgeCommandFailureArtifacts,
|
2026-04-26 19:35:52 +08:00
|
|
|
recordRustBridgeCommandArtifacts,
|
2026-04-15 20:01:12 +08:00
|
|
|
} from "@/lib/documents/bridge-log";
|
2026-04-26 19:35:52 +08:00
|
|
|
import {
|
|
|
|
|
executeRustBridgeMutationTransport,
|
|
|
|
|
resolveRustBridgeCommandPlan,
|
|
|
|
|
} from "@/lib/documents/rust-runtime";
|
2026-04-15 03:34:52 +08:00
|
|
|
|
|
|
|
|
export type MediaAssetReplaceStoragePayload = {
|
|
|
|
|
assetId: string;
|
|
|
|
|
documentId: string;
|
|
|
|
|
workspaceId: string | null;
|
|
|
|
|
storageId: string;
|
|
|
|
|
userId: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type MediaAssetWritebackExecutionResult = {
|
|
|
|
|
requestId: string;
|
|
|
|
|
traceId: string;
|
|
|
|
|
commandId: string;
|
|
|
|
|
commandName: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export async function executeMediaAssetWritebackBridgeCommand(input: {
|
|
|
|
|
client: ConvexHttpClient;
|
|
|
|
|
context: BridgeContext;
|
|
|
|
|
envelope: CommandEnvelope<MediaAssetReplaceStoragePayload>;
|
|
|
|
|
}): Promise<MediaAssetWritebackExecutionResult> {
|
2026-04-26 19:35:52 +08:00
|
|
|
const plan = await resolveRustBridgeCommandPlan({
|
2026-04-15 03:34:52 +08:00
|
|
|
context: input.context,
|
|
|
|
|
envelope: input.envelope,
|
|
|
|
|
});
|
2026-04-15 20:01:12 +08:00
|
|
|
try {
|
2026-04-26 19:35:52 +08:00
|
|
|
const transportResult = await executeRustBridgeMutationTransport({
|
2026-04-15 20:01:12 +08:00
|
|
|
client: input.client,
|
2026-04-26 19:35:52 +08:00
|
|
|
plan,
|
|
|
|
|
});
|
|
|
|
|
await recordRustBridgeCommandArtifacts({
|
|
|
|
|
client: input.client,
|
|
|
|
|
context: input.context,
|
|
|
|
|
envelope: input.envelope,
|
|
|
|
|
plan,
|
|
|
|
|
result: transportResult,
|
2026-04-15 20:01:12 +08:00
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
await recordBridgeCommandFailureArtifacts({
|
|
|
|
|
client: input.client,
|
|
|
|
|
context: input.context,
|
|
|
|
|
envelope: input.envelope,
|
|
|
|
|
error,
|
|
|
|
|
});
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-04-15 03:34:52 +08:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
requestId: input.context.requestId,
|
|
|
|
|
traceId: input.context.traceId,
|
|
|
|
|
commandId: input.envelope.commandId,
|
|
|
|
|
commandName: input.envelope.name,
|
|
|
|
|
};
|
|
|
|
|
}
|