Skip to content

feat: 优化洞察卡片样式与 AI 语义呈现 - #74

Merged
hustcc merged 4 commits into
mainfrom
feat/insight-cards
Nov 19, 2026
Merged

hustcc merged 4 commits into
mainfrom
feat/insight-cards

Conversation

@interstellarmt

Copy link
Copy Markdown
Member
  • 统一 Snippet 和对话图表的便签风格与客户端主题
  • 通过 AI 生成 T8 洞察、分析意图、标签和标题高亮
  • 完善洞察展开、Snippet 保存和编辑交互
image image

Copilot AI balanced review requested due to automatic review settings November 19, 2026 07:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unvalidated AI presentations can alter and persist summary content, while legacy saved charts lose rendering support and long snippet titles can make confirmation buttons inaccessible.

3 open issues
What changed in this PR

This PR unifies analysis charts and saved Snippets with a paper-note design and client-aware themes. It also adds AI-generated insight annotations and improves saving, editing, and expanding insights.

Changes:

  • Generate and persist analysis intent, tags, T8 annotations, and title highlights.
  • Share insight-card components across conversations and Snippets, with light/dark chart themes.
  • Improve Snippet interactions and add AI integration and persistence tests.
File Description
tests/​main/​services/​snippet/​index.test.ts Tests metadata persistence, editing, and legacy inputs.
tests/​main/​ai/​tools.test.ts Tests presentation integration and cancellation forwarding.
tests/​main/​ai/​insight.test.ts Tests generation, fallback, cancellation, and JSON mode.
src/​shared/​snippets.ts Adds optional presentation metadata.
src/​shared/​messages.ts Removes the legacy chart HTML type.
src/​shared/​insight.ts Defines presentation validation and tag deduplication.
src/​renderer/​theme.ts Defines client-aligned chart themes.
src/​renderer/​styles.css Adds chart palette variables.
src/​renderer/​pages/​snippets/​index.tsx Restyles cards and updates editing and deletion interactions.
src/​renderer/​pages/​analysis/​AnalysisMessage.tsx Integrates insight cards and adjusts analysis expansion.
src/​renderer/​pages/​analysis/​AnalysisChart.tsx Adds conversation insight cards and saving controls.
src/​renderer/​components/​Visualization.tsx Applies client themes and handles summary visualizations.
src/​renderer/​components/​InsightSummary.tsx Renders T8 summaries with Markdown fallback.
src/​renderer/​components/​InsightCard.tsx Adds shared labels, highlights, notes, and figures.
src/​renderer/​App.tsx Provides theme context and synchronizes document styling.
src/​main/​services/​snippet/​index.ts Persists metadata and invalidates it after edits.
src/​main/​ai/​tools.ts Attaches presentation metadata to visualization results.
src/​main/​ai/​insight.ts Generates structured insight presentation through AI.
src/​main/​ai/​agent.ts Supplies the original question to presentation generation.
package.json Updates the GPT-Vis dependency range.
assets/​textures/​paper-grain.svg Adds the shared paper texture.

Review effort: Balanced

timeout: 120_000,
maxRetries: 0,
});
return { ...output, tags: [...new Set(output.tags)] };
Comment on lines 455 to 456
{message.content.text && <Markdown>{message.content.text}</Markdown>}
<Chart html={message.content.chartHtml} />
<AnalysisTable analysis={message.content} />
<AlertDialog.Root open={!!deleting} onOpenChange={(open) => !busy && !open && setDeleting(null)}>
<AlertDialog.Portal>
<AlertDialog.Overlay className="fixed inset-0 z-50 bg-[#15202bcc]" />
<AlertDialog.Content className="fixed top-1/2 left-1/2 z-50 w-[480px] max-w-[calc(100vw-32px)] -translate-x-1/2 -translate-y-1/2 rounded-2xl border bg-surface p-6 shadow-2xl">
Comment thread src/main/ai/agent.ts Outdated
ava,
dataset,
() => options.strategy,
(analysis, spec, abortSignal) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

传入 createTools 必要的参数,然后在 createTools 去组合其他 agent。

Comment thread src/main/ai/snippet-agent.ts Resolved
Comment thread src/renderer/components/InsightCard.tsx Outdated
@@ -0,0 +1,195 @@
import {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以抽离下所有的 snippet-layout 到一个目录中,然后后续增加布局模版,就是在这个目录新增组件,然后注册到模版池子里面。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

概念一致,不新增概念,可以使用 SnippetCart,看到名字就知道是哪里的 ui。和功能。

Comment thread vitest.config.ts

export default defineConfig({
resolve: {
alias: { '@shared': resolve('src/shared') },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

electron.vite.config.ts 应该有类似功能。

Comment thread src/shared/schema.ts Outdated
question: string;
spec: SnippetSpec;
summary: string;
presentation?: InsightPresentation;

@hustcc hustcc Nov 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个结构可以拍平,不做嵌套,也不用兼容就得数据,保持干净。这里的改动会牵动其他地方的改动。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • question

  • intent

  • title

  • summary

  • spec

  • tags

Comment thread src/main/ai/agent.ts Outdated
abortSignal,
}),
),
tools: createTools(ava, dataset, options, languageModel),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options 需要使用回调方法,估计 languageModel 也需要,涉及到 setting 那边修改之后,这边要更新。可能需要测测。

Comment thread src/main/ai/tools.ts Outdated
} from '@antv/ava';
import { localFilePath } from '../util/localFile';
import type { SnippetContent } from '@shared/schema';
import { generateInsightPresentation } from './snippet-agent';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateSnippet

Comment thread tests/main/ai/snippet-agent.test.ts Outdated
@@ -2,7 +2,7 @@ import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种 ai agent 单测依赖 llm,mock 之后测不出啥东西,可以不加的。现在加单侧的基本都是纯函数。

Comment thread src/main/ai/tools.ts
summary: formatted?.summary ?? analysis.text,
spec,
tags: formatted?.tags ?? [],
metrics: formatted?.metrics ?? [],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍,很清晰了

Comment thread src/main/db/ddl.ts
summary TEXT NOT NULL,
spec TEXT NOT NULL,
tags TEXT NOT NULL,
metrics TEXT NOT NULL,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在是分开字段存,不合到大 json 字段吗?

'min-w-0 text-sm leading-7 text-pretty tabular-nums [&_.gpt-vis-summary]:bg-transparent! [&_.gpt-vis-summary]:p-0! [&_.t8-p]:m-0! [&_.t8-p]:text-sm! [&_.t8-p]:leading-7!';

export const summaryToggleClassName =
'mt-2 inline-flex items-center gap-1 p-0 text-xs leading-5 text-muted hover:text-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这些不用复用,设想要自己写模板了,用户会有这些复用的吗?

不过这个对目前是小问题。

@hustcc

hustcc commented Nov 19, 2026

Copy link
Copy Markdown
Member

是不是模板和主题有点搞混淆了?

@hustcc
hustcc merged commit 314b708 into main Nov 19, 2026
2 checks passed
@hustcc
hustcc deleted the feat/insight-cards branch November 19, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants