mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
fix: should save chat to block when doc mode (#7697)
[BS-1033](https://linear.app/affine-design/issue/BS-1033/在page模式下尝试存chat-block,被告知失败,预期是切换到白板模式直接操作成功)
This commit is contained in:
@@ -110,7 +110,7 @@ function getViewportCenter(
|
|||||||
mode: DocMode,
|
mode: DocMode,
|
||||||
rootService: PageRootService | EdgelessRootService
|
rootService: PageRootService | EdgelessRootService
|
||||||
) {
|
) {
|
||||||
const center = { x: 0, y: 0 };
|
const center = { x: 400, y: 50 };
|
||||||
if (mode === 'page') {
|
if (mode === 'page') {
|
||||||
const viewport = rootService.editPropsStore.getStorage('viewport');
|
const viewport = rootService.editPropsStore.getStorage('viewport');
|
||||||
if (viewport) {
|
if (viewport) {
|
||||||
@@ -138,7 +138,8 @@ function addAIChatBlock(
|
|||||||
host: EditorHost,
|
host: EditorHost,
|
||||||
messages: ChatMessage[],
|
messages: ChatMessage[],
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
viewportCenter: { x: number; y: number }
|
viewportCenter: { x: number; y: number },
|
||||||
|
index: string
|
||||||
) {
|
) {
|
||||||
if (!messages.length || !sessionId) {
|
if (!messages.length || !sessionId) {
|
||||||
return;
|
return;
|
||||||
@@ -152,8 +153,6 @@ function addAIChatBlock(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const surfaceService = host.spec.getService('affine:surface');
|
|
||||||
const { layer } = surfaceService;
|
|
||||||
// Add AI chat block to the center of the viewport
|
// Add AI chat block to the center of the viewport
|
||||||
const width = 300; // AI_CHAT_BLOCK_WIDTH = 300
|
const width = 300; // AI_CHAT_BLOCK_WIDTH = 300
|
||||||
const height = 320; // AI_CHAT_BLOCK_HEIGHT = 320
|
const height = 320; // AI_CHAT_BLOCK_HEIGHT = 320
|
||||||
@@ -165,7 +164,7 @@ function addAIChatBlock(
|
|||||||
{
|
{
|
||||||
xywh: bound.serialize(),
|
xywh: bound.serialize(),
|
||||||
messages: JSON.stringify(messages),
|
messages: JSON.stringify(messages),
|
||||||
index: layer.generateIndex('affine:embed-ai-chat'),
|
index,
|
||||||
sessionId,
|
sessionId,
|
||||||
rootWorkspaceId: doc.collection.id,
|
rootWorkspaceId: doc.collection.id,
|
||||||
rootDocId: doc.id,
|
rootDocId: doc.id,
|
||||||
@@ -300,11 +299,14 @@ const SAVE_CHAT_TO_BLOCK_ACTION: ChatAction = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rootService = host.spec.getService('affine:page');
|
const rootService = host.spec.getService('affine:page');
|
||||||
if (!rootService) return false;
|
const surfaceService = host.spec.getService('affine:surface');
|
||||||
|
if (!rootService || !surfaceService) return false;
|
||||||
|
|
||||||
const { docModeService, notificationService } = rootService;
|
const { docModeService, notificationService } = rootService;
|
||||||
|
const { layer } = surfaceService;
|
||||||
const curMode = docModeService.getMode();
|
const curMode = docModeService.getMode();
|
||||||
const viewportCenter = getViewportCenter(curMode, rootService);
|
const viewportCenter = getViewportCenter(curMode, rootService);
|
||||||
|
const newBlockIndex = layer.generateIndex('affine:embed-ai-chat');
|
||||||
// If current mode is not edgeless, switch to edgeless mode first
|
// If current mode is not edgeless, switch to edgeless mode first
|
||||||
if (curMode !== 'edgeless') {
|
if (curMode !== 'edgeless') {
|
||||||
// Set mode to edgeless
|
// Set mode to edgeless
|
||||||
@@ -342,7 +344,8 @@ const SAVE_CHAT_TO_BLOCK_ACTION: ChatAction = {
|
|||||||
host,
|
host,
|
||||||
messages,
|
messages,
|
||||||
newSessionId,
|
newSessionId,
|
||||||
viewportCenter
|
viewportCenter,
|
||||||
|
newBlockIndex
|
||||||
);
|
);
|
||||||
if (!blockId) {
|
if (!blockId) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user