fix: support canvas view prompts without context payload
This commit is contained in:
parent
8913daa2b0
commit
89b4a82e62
@ -881,6 +881,16 @@ export async function POST(request: Request) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
const isCanvasPageRequest = (() => {
|
||||||
|
const referer = request.headers.get("referer");
|
||||||
|
if (!referer) return false;
|
||||||
|
try {
|
||||||
|
const pathname = new URL(referer).pathname;
|
||||||
|
return pathname === "/canvas" || pathname.startsWith("/canvas/");
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})();
|
||||||
const requestTextContent = message.parts
|
const requestTextContent = message.parts
|
||||||
.filter((part): part is { type: "text"; text: string } => part.type === "text")
|
.filter((part): part is { type: "text"; text: string } => part.type === "text")
|
||||||
.map((part) => part.text)
|
.map((part) => part.text)
|
||||||
@ -900,7 +910,8 @@ export async function POST(request: Request) {
|
|||||||
composerMode !== "agent" &&
|
composerMode !== "agent" &&
|
||||||
(contextPayload?.source === "canvas" ||
|
(contextPayload?.source === "canvas" ||
|
||||||
contextPayload?.source === "realtime-canvas" ||
|
contextPayload?.source === "realtime-canvas" ||
|
||||||
Boolean(requestCanvasAgentContext)) &&
|
Boolean(requestCanvasAgentContext) ||
|
||||||
|
isCanvasPageRequest) &&
|
||||||
shouldBypassCanvasImagePointsPrecheckForAgentControl({
|
shouldBypassCanvasImagePointsPrecheckForAgentControl({
|
||||||
text: requestTextContent,
|
text: requestTextContent,
|
||||||
activeComposerMode: composerMode,
|
activeComposerMode: composerMode,
|
||||||
@ -3213,8 +3224,11 @@ export async function POST(request: Request) {
|
|||||||
const resolveCanvasViewOperationPlan = (): CanvasViewOperationPlan | null => {
|
const resolveCanvasViewOperationPlan = (): CanvasViewOperationPlan | null => {
|
||||||
if (!canvasAgentFeatures.viewOperationEnabled) return null;
|
if (!canvasAgentFeatures.viewOperationEnabled) return null;
|
||||||
if (composerMode !== "agent" && !hasCanvasControlIntentFastPath) return null;
|
if (composerMode !== "agent" && !hasCanvasControlIntentFastPath) return null;
|
||||||
if (contextPayload?.source !== "canvas" || !contextPayload.projectId) return null;
|
const projectId =
|
||||||
if (!requestCanvasAgentContext) return null;
|
contextPayload?.projectId ||
|
||||||
|
requestCanvasAgentContext?.projectId ||
|
||||||
|
(hasCanvasControlIntentFastPath ? id : undefined);
|
||||||
|
if (!projectId) return null;
|
||||||
|
|
||||||
const text = requestTextContent.trim();
|
const text = requestTextContent.trim();
|
||||||
if (!text) return null;
|
if (!text) return null;
|
||||||
@ -3234,10 +3248,48 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const viewOperationId = `${message.id}:canvas-view:${Date.now()}`;
|
const viewOperationId = `${message.id}:canvas-view:${Date.now()}`;
|
||||||
|
|
||||||
|
if (!requestCanvasAgentContext) {
|
||||||
|
if (/看全局|看整体|看全部|全局|整体/.test(lowerText)) {
|
||||||
|
return {
|
||||||
|
version: 1,
|
||||||
|
viewOperationId,
|
||||||
|
operation: "fit_all",
|
||||||
|
projectId,
|
||||||
|
padding: 140,
|
||||||
|
persist: false,
|
||||||
|
reason: "fit_all_canvas",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/缩小|拉远|zoom\s*out/.test(lowerText)) {
|
||||||
|
return {
|
||||||
|
version: 1,
|
||||||
|
viewOperationId,
|
||||||
|
operation: "zoom_out",
|
||||||
|
projectId,
|
||||||
|
persist: false,
|
||||||
|
reason: "zoom_out_canvas",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/放大|拉近|zoom\s*in/.test(lowerText)) {
|
||||||
|
return {
|
||||||
|
version: 1,
|
||||||
|
viewOperationId,
|
||||||
|
operation: "zoom_in",
|
||||||
|
projectId,
|
||||||
|
persist: false,
|
||||||
|
reason: "zoom_in_canvas",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasLatestResultViewIntent) {
|
if (hasLatestResultViewIntent) {
|
||||||
const latestResultViewPlan = buildCanvasAgentLatestResultViewPlan({
|
const latestResultViewPlan = buildCanvasAgentLatestResultViewPlan({
|
||||||
userText: text,
|
userText: text,
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
operationId: viewOperationId,
|
operationId: viewOperationId,
|
||||||
});
|
});
|
||||||
if (latestResultViewPlan) return latestResultViewPlan;
|
if (latestResultViewPlan) return latestResultViewPlan;
|
||||||
@ -3270,7 +3322,7 @@ export async function POST(request: Request) {
|
|||||||
if (hasComparisonViewIntent) {
|
if (hasComparisonViewIntent) {
|
||||||
const comparisonViewPlan = buildCanvasAgentComparisonViewPlan({
|
const comparisonViewPlan = buildCanvasAgentComparisonViewPlan({
|
||||||
context: requestCanvasAgentContext,
|
context: requestCanvasAgentContext,
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
operationId: viewOperationId,
|
operationId: viewOperationId,
|
||||||
});
|
});
|
||||||
if (comparisonViewPlan) return comparisonViewPlan;
|
if (comparisonViewPlan) return comparisonViewPlan;
|
||||||
@ -3281,7 +3333,7 @@ export async function POST(request: Request) {
|
|||||||
version: 1,
|
version: 1,
|
||||||
viewOperationId,
|
viewOperationId,
|
||||||
operation: "fit_all",
|
operation: "fit_all",
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
padding: 140,
|
padding: 140,
|
||||||
persist: false,
|
persist: false,
|
||||||
reason: "fit_all_canvas",
|
reason: "fit_all_canvas",
|
||||||
@ -3293,7 +3345,7 @@ export async function POST(request: Request) {
|
|||||||
version: 1,
|
version: 1,
|
||||||
viewOperationId,
|
viewOperationId,
|
||||||
operation: "zoom_out",
|
operation: "zoom_out",
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
persist: false,
|
persist: false,
|
||||||
reason: "zoom_out_canvas",
|
reason: "zoom_out_canvas",
|
||||||
};
|
};
|
||||||
@ -3313,7 +3365,7 @@ export async function POST(request: Request) {
|
|||||||
version: 1,
|
version: 1,
|
||||||
viewOperationId,
|
viewOperationId,
|
||||||
operation: nodeIds.length > 1 ? "focus_nodes" : "focus_selection",
|
operation: nodeIds.length > 1 ? "focus_nodes" : "focus_selection",
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
nodeIds,
|
nodeIds,
|
||||||
anchorNodeId: anchorNode?.nodeId,
|
anchorNodeId: anchorNode?.nodeId,
|
||||||
padding: 120,
|
padding: 120,
|
||||||
@ -3326,7 +3378,7 @@ export async function POST(request: Request) {
|
|||||||
const panViewPlan = buildCanvasAgentPanViewPlan({
|
const panViewPlan = buildCanvasAgentPanViewPlan({
|
||||||
userText: text,
|
userText: text,
|
||||||
context: requestCanvasAgentContext,
|
context: requestCanvasAgentContext,
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
operationId: viewOperationId,
|
operationId: viewOperationId,
|
||||||
});
|
});
|
||||||
if (panViewPlan) return panViewPlan;
|
if (panViewPlan) return panViewPlan;
|
||||||
@ -3337,7 +3389,7 @@ export async function POST(request: Request) {
|
|||||||
version: 1,
|
version: 1,
|
||||||
viewOperationId,
|
viewOperationId,
|
||||||
operation: "zoom_in",
|
operation: "zoom_in",
|
||||||
projectId: contextPayload.projectId,
|
projectId,
|
||||||
persist: false,
|
persist: false,
|
||||||
reason: "zoom_in_canvas",
|
reason: "zoom_in_canvas",
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user