feat: 深度研究支持独立新报告与原文改写,并完善沙箱、模型管理与全文改写

新报告不再覆盖当前文件卡片,写入时打开沙箱;步骤条仅在改写原文时位于卡片上方。同时补齐改写本地回退、模型管理与会商第三步相关改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
董宏凯andCursor committed 2026-08-21 21:46:04 +08:00
1 parent 11f928bc95
commit a5a9c952e8
63 files changed
+4113 -929

No files matched your search

@@ -339,9 +339,10 @@ export interface StartJobOptions {
requestId?: string;
/**
* "chat" harvests the collector-agent conversation's materials as the pool;
* "legacy" (default) keeps the runner-driven search tiers.
* "legacy" (default) keeps the runner-driven search tiers; "regenerate"
* runs the same report engine again over the variant's selected source pool.
*/
entry?: "chat" | "legacy";
entry?: "chat" | "legacy" | "regenerate";
/** Report-config card choices merged over the frozen session snapshot. */
config?: Record<string, unknown>;
}
@@ -629,6 +630,36 @@ export function streamResearchRewrite(
return streamResearchMessage(sessionId, instruction, handlers, signal, "rewrite");
}
export async function listReportVariants(parentSessionId: string): Promise<DeepResearchSession[]> {
const res = await apiFetch(
`${BASE()}/sessions/${encodeURIComponent(parentSessionId)}/report-variants`,
{ method: "GET" },
);
const data = await readJson<WireRecord>(res, "listReportVariants");
return asItems(data.items).map(normalizeSession);
}
/**
* Fork a completed report before generating it under another structure.
* The returned session owns its own report and selected-source snapshot, so
* its durable rewrite cannot replace the parent report.
*/
export async function createResearchReportVariant(
sessionId: string,
input: { reportOutline?: string },
): Promise<DeepResearchSession> {
const response = await apiFetch(
`${BASE()}/sessions/${encodeURIComponent(sessionId)}/report-variants`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
},
);
const data = await readJson<WireRecord>(response, "createResearchReportVariant");
return normalizeSession(data);
}
export async function cancelFullResearchReportRewrite(jobId: string): Promise<void> {
await cancelJob(jobId);
}
@@ -636,7 +667,13 @@ export async function cancelFullResearchReportRewrite(jobId: string): Promise<vo
export interface LatestFullReportRewrite {
job: DeepResearchJob | null;
result: Record<string, unknown>;
request: { instruction: string; style: DocumentRewriteStyle; modelName?: string | null };
request: {
operation: "rewrite" | "generate";
instruction: string;
style: DocumentRewriteStyle;
modelName?: string | null;
reportOutline?: string;
};
}
export async function getLatestFullResearchReportRewrite(
@@ -653,9 +690,11 @@ export async function getLatestFullResearchReportRewrite(
job: jobRecord ? normalizeJob(jobRecord) : null,
result: asRecord(data.result),
request: {
operation: request.operation === "generate" ? "generate" : "rewrite",
instruction: String(request.instruction ?? ""),
style: (request.style ?? "formal_analysis") as DocumentRewriteStyle,
modelName: typeof request.modelName === "string" ? request.modelName : null,
reportOutline: typeof request.reportOutline === "string" ? request.reportOutline : "",
},
};
}
@@ -745,6 +784,11 @@ export async function* joinFullResearchReportRewrite(
modelName: String(raw.modelName ?? "deep_research_smart_model"),
plan: typeof raw.plan === "string" ? raw.plan : undefined,
};
} else if (type === "thinking") {
// Deep Research uses the same shared rewrite hook/timeline as
// sandbox Markdown. Preserve provider reasoning chunks instead
// of silently dropping them in this custom durable-SSE adapter.
yield { type, chunk: String(raw.chunk ?? "") };
} else if (type === "rewrite_delta") {
yield { type, delta: String(raw.delta ?? ""), charCount: Number(raw.charCount ?? 0) };
} else if (type === "rewrite_checkpoint") {
@@ -767,12 +811,14 @@ export async function* joinFullResearchReportRewrite(
content: String(raw.content ?? ""),
committedHash: String(raw.committedHash ?? ""),
versionId: typeof raw.versionId === "string" ? raw.versionId : undefined,
versionSnapshotFailed: raw.versionSnapshotFailed === true,
};
} else if (type === "done") {
yield {
type,
committedHash: String(raw.committedHash ?? ""),
versionId: typeof raw.versionId === "string" ? raw.versionId : undefined,
versionSnapshotFailed: raw.versionSnapshotFailed === true,
};
terminal = true;
} else if (type === "conflict") {
@@ -808,7 +854,13 @@ export async function* joinFullResearchReportRewrite(
/** Start and join the sandbox's durable complete-report rewrite. */
export async function* streamFullResearchReportRewrite(
sessionId: string,
input: { instruction: string; style: DocumentRewriteStyle; modelName?: string },
input: {
operation?: "rewrite" | "generate";
instruction: string;
style: DocumentRewriteStyle;
modelName?: string;
reportOutline?: string;
},
signal?: AbortSignal,
onJobStarted?: (jobId: string) => void,
): AsyncGenerator<DocumentRewriteStreamEvent> {
@@ -877,6 +929,7 @@ export const DEEP_RESEARCH_SESSION_KEY = "deep-research-session";
export const DEEP_RESEARCH_SOURCES_KEY = "deep-research-sources";
export const DEEP_RESEARCH_MESSAGES_KEY = "deep-research-messages";
export const DEEP_RESEARCH_CAPABILITIES_KEY = "deep-research-capabilities";
export const DEEP_RESEARCH_REPORT_VARIANTS_KEY = "deep-research-report-variants";
export function useResearchSessions(limit = 50) {
return useQuery({
@@ -896,6 +949,15 @@ export function useResearchSession(id: string | null) {
});
}
export function useResearchReportVariants(parentSessionId: string | null) {
return useQuery({
queryKey: [DEEP_RESEARCH_REPORT_VARIANTS_KEY, parentSessionId],
queryFn: () => listReportVariants(parentSessionId!),
enabled: !!parentSessionId,
refetchOnWindowFocus: false,
});
}
export function useResearchSources(sessionId: string | null) {
return useQuery({
queryKey: [DEEP_RESEARCH_SOURCES_KEY, sessionId],
@@ -939,7 +1001,7 @@ export function useResearchActions() {
config,
}: {
sessionId: string;
entry?: "chat" | "legacy";
entry?: "chat" | "legacy" | "regenerate";
config?: Record<string, unknown>;
}) => startJob(sessionId, { entry, config }),
onSuccess: (_result, { sessionId }) => {
@@ -6,6 +6,7 @@
*/
import type { LightApp, LightAppRouteParam } from "@/strategy-components/api/light-apps";
import { getStoredAuth } from "@/core/auth";
import { authStorageGet } from "@/core/auth/scoped-storage";
import { readCurrentExternalAccessTokenValue } from "@/core/auth/external-access-token";
@@ -26,13 +27,14 @@ export function mountLabel(value: string | null | undefined): string {
/**
* 登录参数可选来源;值均可在 userInfo 中取到,"other" 表示自填。
* accessToken / yUserId 取登录路由透传值(写入 userInfo 的同名键);
* userName / gateDepartName / typeName 取 consumer 接口 userDetailByYuserId 的返回值。
* userName 优先取当前鉴权会话的原始登录名;gateDepartName / typeName 取 consumer
* 接口 userDetailByYuserId 的返回值。
*/
export const LOGIN_SOURCE_OPTIONS: { label: string; value: string }[] = [
{ label: "access_token", value: "access_token" },
{ label: "accessToken(兼容旧配置)", value: "accessToken" },
{ label: "yUserId", value: "yUserId" },
{ label: "userName", value: "userName" },
{ label: "userName(当前登录账号)", value: "userName" },
{ label: "gateDepartName", value: "gateDepartName" },
{ label: "typeName", value: "typeName" },
{ label: "其他(自定义值)", value: "other" },
@@ -152,6 +154,25 @@ export function resolveRouteParamValue(
return param.customValue ?? "";
}
if (param.source) {
// `userInfo.userName` can belong to a prior external-login flow (for
// example a stale "guest" value). Route parameters must follow the user
// currently authenticated in DeerFlow, so prefer the backend's original
// login username and only fall back to userInfo for older backends.
if (param.source === "userName") {
const auth = getStoredAuth();
const loginUsername = auth?.username?.trim();
if (loginUsername) return loginUsername;
const accountName = (auth?.email ?? "").split("@")[0]?.trim() || auth?.user_id;
if (accountName) return accountName;
const userInfoName = userInfo.userName;
if (typeof userInfoName === "string" && userInfoName.trim()) {
return userInfoName.trim();
}
return "";
}
const value = userInfo[param.source];
if (param.source === "access_token" || param.source === "accessToken") {
return readCurrentExternalAccessTokenValue(userInfo);