sync snapshot from LAN repo (source feat/tailwind-v3-legacy-chrome @ 2fdce2d3)

This commit is contained in:
gozeros committed 2026-11-05 11:05:46 +08:00
1 parent ea9dcff9c0
commit 6b1ad5a3e5
1458 files changed
+31752 -174864

No files matched your search

@@ -1,30 +1,13 @@
"use client";
import { createContext, useCallback, useContext, useMemo, useRef, useState } from "react";
import { createContext, useCallback, useContext, useMemo, useState } from "react";
import type {
DocumentRewriteStage,
} from "@/open-canvas/hooks/useDocumentRewrite";
import {
cancelDurableDocumentRewrite,
type DocumentRewriteDiagnostic,
type DocumentRewriteSummary,
} from "@/open-canvas/api/rewrite";
import type { DocumentRewriteSummary } from "@/open-canvas/api/rewrite";
import { createClientId } from "@/lib/client-id";
const ACTIVE_DOCUMENT_REWRITE_STAGES: DocumentRewriteStage[] = [
"snapshot",
"requirements",
"writing",
"illustrating",
"validation",
"committing",
];
export function isDocumentRewriteActiveStage(stage: DocumentRewriteStage) {
return ACTIVE_DOCUMENT_REWRITE_STAGES.includes(stage);
}
export type DocumentRewritePresentation = {
id: string;
threadId: string;
@@ -35,8 +18,6 @@ export type DocumentRewritePresentation = {
id: string;
path?: string;
};
/** Separate artifact created for this rewrite; the source file remains unchanged. */
outputPath: string | null;
fileName: string;
instruction: string;
style: string;
@@ -58,8 +39,6 @@ export type DocumentRewritePresentation = {
originalContent: string;
rewrittenContent: string | null;
versionId: string | null;
/** Durable job identity. Enables cancellation after a page or sandbox remount. */
jobId: string | null;
/** Hash of the currently committed rewrite, used by the local undo fallback. */
committedHash: string | null;
/** A browser-only undo backup is available because the server snapshot failed. */
@@ -68,7 +47,6 @@ export type DocumentRewritePresentation = {
redoVersionId: string | null;
revertedAt: string | null;
error: string | null;
diagnostic: DocumentRewriteDiagnostic | null;
createdAt: string;
updatedAt: string;
};
@@ -78,7 +56,6 @@ type CreatePresentationInput = Omit<
| "id"
| "stage"
| "operation"
| "outputPath"
| "generateImages"
| "maxGeneratedImages"
| "generatedImageCount"
@@ -92,22 +69,18 @@ type CreatePresentationInput = Omit<
| "originalContent"
| "rewrittenContent"
| "versionId"
| "jobId"
| "committedHash"
| "localFallbackAvailable"
| "redoVersionId"
| "revertedAt"
| "error"
| "diagnostic"
| "createdAt"
| "updatedAt"
> & {
operation?: DocumentRewritePresentation["operation"];
outputPath?: string | null;
originalContent?: string;
rewrittenContent?: string | null;
committedHash?: string | null;
jobId?: string | null;
localFallbackAvailable?: boolean;
requirementsPlan?: string;
generateImages?: boolean;
@@ -121,19 +94,6 @@ type DocumentRewritePresentationContextValue = {
patch: Partial<Omit<DocumentRewritePresentation, "id" | "threadId" | "createdAt">>,
) => void;
forThread: (threadId: string) => DocumentRewritePresentation[];
/**
* Binds a live sandbox stream to its in-feed presentation. The shared
* composer uses this before falling back to the durable cancellation API.
*/
registerCancellation: (
presentationId: string,
cancel: () => void | Promise<void>,
) => () => void;
/** Stop every active rewrite visible in this conversation. */
cancelActiveForThread: (threadId: string) => Promise<{
cancelled: boolean;
error?: string;
}>;
};
const DocumentRewritePresentationContext =
@@ -149,9 +109,6 @@ export function DocumentRewritePresentationProvider({
children: React.ReactNode;
}) {
const [presentations, setPresentations] = useState<DocumentRewritePresentation[]>([]);
const cancellationHandlersRef = useRef<
Map<string, () => void | Promise<void>>
>(new Map());
const create = useCallback((input: CreatePresentationInput) => {
const id = createId();
@@ -163,7 +120,6 @@ export function DocumentRewritePresentationProvider({
id,
stage: "snapshot",
operation: input.operation ?? "rewrite",
outputPath: input.outputPath ?? null,
generateImages: input.generateImages === true,
maxGeneratedImages: Math.min(Math.max(input.maxGeneratedImages ?? 2, 1), 4),
generatedImageCount: 0,
@@ -177,13 +133,11 @@ export function DocumentRewritePresentationProvider({
originalContent: input.originalContent ?? "",
rewrittenContent: input.rewrittenContent ?? null,
versionId: null,
jobId: input.jobId ?? null,
committedHash: input.committedHash ?? null,
localFallbackAvailable: input.localFallbackAvailable === true,
redoVersionId: null,
revertedAt: null,
error: null,
diagnostic: null,
createdAt: now,
updatedAt: now,
},
@@ -218,83 +172,14 @@ export function DocumentRewritePresentationProvider({
[],
);
const registerCancellation = useCallback(
(presentationId: string, cancel: () => void | Promise<void>) => {
cancellationHandlersRef.current.set(presentationId, cancel);
return () => {
if (cancellationHandlersRef.current.get(presentationId) === cancel) {
cancellationHandlersRef.current.delete(presentationId);
}
};
},
[],
);
const cancelActiveForThread = useCallback(
async (threadId: string) => {
const active = presentations.filter(
(item) => item.threadId === threadId && isDocumentRewriteActiveStage(item.stage),
);
if (active.length === 0) return { cancelled: false };
const errors: string[] = [];
let cancelled = false;
await Promise.all(
active.map(async (item) => {
const cancel = cancellationHandlersRef.current.get(item.id);
if (cancel) {
try {
await cancel();
cancelled = true;
} catch (error) {
errors.push(error instanceof Error ? error.message : "停止全文改写失败");
}
return;
}
if (
item.source.kind !== "artifact" ||
!item.source.path ||
!item.jobId
) {
errors.push("改写任务尚未就绪,请稍候再试。");
return;
}
try {
await cancelDurableDocumentRewrite(
{ threadId: item.source.id, path: item.source.path },
item.jobId,
);
update(item.id, {
stage: "cancelled",
error: "已停止全文改写,原文件未被修改。",
});
cancelled = true;
} catch (error) {
errors.push(error instanceof Error ? error.message : "停止全文改写失败");
}
}),
);
return {
cancelled,
...(errors.length > 0 ? { error: errors[0] } : {}),
};
},
[presentations, update],
);
const value = useMemo<DocumentRewritePresentationContextValue>(
() => ({
create,
update,
forThread: (threadId) =>
presentations.filter((item) => item.threadId === threadId),
registerCancellation,
cancelActiveForThread,
}),
[cancelActiveForThread, create, presentations, registerCancellation, update],
[create, presentations, update],
);
return (