From 3cc33bd40f8f39c4a910adaf73d5b49cb4cc2e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=B8=83=E5=8A=B3=E5=A4=96=20=C2=B7=20=E8=B4=BE?= =?UTF-8?q?=E8=B4=B5?= <472285740@qq.com> Date: Wed, 9 Jul 2025 11:55:17 +0800 Subject: [PATCH] fix(core): apply model ui (#13084) --- .../src/plugins/copilot/tools/doc-edit.ts | 2 +- .../ai/components/ai-tools/doc-edit.ts | 39 ++++++------------- .../blocksuite/ai/widgets/block-diff/block.ts | 35 +++++++++++------ .../blocksuite/ai/widgets/block-diff/page.ts | 6 ++- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/packages/backend/server/src/plugins/copilot/tools/doc-edit.ts b/packages/backend/server/src/plugins/copilot/tools/doc-edit.ts index cc4a7760d..ed1ee64fe 100644 --- a/packages/backend/server/src/plugins/copilot/tools/doc-edit.ts +++ b/packages/backend/server/src/plugins/copilot/tools/doc-edit.ts @@ -167,7 +167,7 @@ You should specify the following arguments before the others: [doc_id], [origin_ }, ]); - return { result }; + return { result, content }; } catch { return 'Failed to apply edit to the doc'; } diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-edit.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-edit.ts index fae4c56de..16394eb2d 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-edit.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-edit.ts @@ -11,7 +11,7 @@ import { PenIcon as EditIcon, PenIcon, } from '@blocksuite/icons/lit'; -import { css, html, nothing, type PropertyValues } from 'lit'; +import { css, html, nothing } from 'lit'; import { property, state } from 'lit/decorators.js'; import type { BlockDiffService } from '../../services/block-diff'; @@ -37,6 +37,7 @@ interface DocEditToolResult { result: | { result: string; + content: string; } | ToolError | null; @@ -197,9 +198,6 @@ export class DocEditTool extends WithDisposable(ShadowlessElement) { @state() accessor isCollapsed = false; - @state() - accessor originalMarkdown: string | undefined; - private async _handleApply(markdown: string) { if (!this.host) { return; @@ -259,11 +257,8 @@ export class DocEditTool extends WithDisposable(ShadowlessElement) { return this.renderRichText(removeMarkdownComments(text)); } - renderBlockDiffs(originalMarkdown: string, changedMarkdown: string) { - const { patches, oldBlocks } = diffMarkdown( - originalMarkdown, - changedMarkdown - ); + renderBlockDiffs(diffs: ReturnType) { + const { patches, oldBlocks } = diffs; const oldBlockMap = new Map(oldBlocks.map(b => [b.id, b])); @@ -311,15 +306,18 @@ export class DocEditTool extends WithDisposable(ShadowlessElement) { } renderToolResult() { - if (this.data.type !== 'tool-result' || !this.originalMarkdown) { + if (this.data.type !== 'tool-result') { return nothing; } const result = this.data.result; - if (result && 'result' in result) { - const changedMarkdown = result.result; + if (result && 'result' in result && 'content' in result) { + const { result: changedMarkdown, content } = result; const { instructions, doc_id: docId } = this.data.args; + + const diffs = diffMarkdown(content, changedMarkdown); + return html`
${instructions}
@@ -351,7 +349,7 @@ export class DocEditTool extends WithDisposable(ShadowlessElement) {
- ${this.renderBlockDiffs(this.originalMarkdown, changedMarkdown)} + ${this.renderBlockDiffs(diffs)}