@legendzd/ai-agent-vue 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -3
- package/dist/index.cjs +59 -59
- package/dist/index.mjs +62174 -61839
- package/dist/src/components/ChatMessage.vue.d.ts +18 -1
- package/dist/src/plugin/index.d.ts +1 -0
- package/dist/src/stores/chat.d.ts +53 -5
- package/dist/src/types/agent.d.ts +28 -1
- package/dist/src/views/AgentChat.vue.d.ts +2 -0
- package/dist/src/views/AgentChatFull.vue.d.ts +2 -0
- package/dist/src/views/AgentChatMobile.vue.d.ts +2 -0
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,8 +8,11 @@
|
|
|
8
8
|
- **多实例隔离** — 通过 `instanceId` 创建独立对话实例,不同用户/场景互不干扰
|
|
9
9
|
- **零配置即插即用** — 内置 Pinia + 持久化,宿主应用无需额外安装状态管理
|
|
10
10
|
- **会话管理** — 自动创建会话、历史记录、一键切换/新建对话
|
|
11
|
-
- **SSE 流式对话** — 支持 status/sql/data/chart_config/sources/analysis_chunk 等富事件类型
|
|
12
|
-
-
|
|
11
|
+
- **SSE 流式对话** — 支持 session/status/sql/data/chart_config/sources/run_plan/analysis_chunk 等富事件类型
|
|
12
|
+
- **分类存储与可配置渲染** — SQL/数据表格默认隐藏,执行计划可折叠,均可通过配置控制显隐
|
|
13
|
+
- **富内容渲染** — Markdown 代码高亮、SQL 可展开复制、结构化数据表格、ECharts 图表(支持暗色主题联动)、编号引用来源、执行计划折叠面板
|
|
14
|
+
- **增强错误样式** — 带左侧色条 + 警告图标的错误提示,深浅色主题适配
|
|
15
|
+
- **结构化数据访问** — 通过实例 ID 或消息 ID 获取 sql/data/chartConfig/sources/runPlan 等结构化数据
|
|
13
16
|
- **深色/浅色主题** — 通过 CSS 变量一键切换或自定义覆盖,所有布局均支持
|
|
14
17
|
- **语音输入** — 基于浏览器 Web Speech API,可配置语言
|
|
15
18
|
- **组件实例 API** — 通过 ref 直接访问对话数据、控制会话
|
|
@@ -380,6 +383,10 @@ destroyChatInstance('user-a')
|
|
|
380
383
|
| `enableVoice` | `boolean` | `true` | 是否启用语音输入(浏览器不支持时自动隐藏) |
|
|
381
384
|
| `voiceLang` | `string` | `'zh-CN'` | 语音识别语言 |
|
|
382
385
|
| `instanceId` | `string` | `'default'` | 实例 ID,用于多实例隔离 |
|
|
386
|
+
| `showSql` | `boolean` | `false` | 是否在消息中显示 SQL 区域 |
|
|
387
|
+
| `showData` | `boolean` | `false` | 是否在消息中显示数据表格区域 |
|
|
388
|
+
| `showRunPlan` | `boolean` | `true` | 是否显示执行计划/思考过程面板 |
|
|
389
|
+
| `defaultRunPlanExpanded` | `boolean` | `false` | 执行计划面板默认是否展开 |
|
|
383
390
|
|
|
384
391
|
### userId 两种写法
|
|
385
392
|
|
|
@@ -563,6 +570,25 @@ const chatRef = ref()
|
|
|
563
570
|
| `--agent-empty-color` | `#5a6b8a` | 空状态文字颜色 |
|
|
564
571
|
| `--agent-error-color` | `#f87171` | 错误文字颜色 |
|
|
565
572
|
| `--agent-error-bg` | `rgba(248,113,113,0.1)` | 错误背景色 |
|
|
573
|
+
| `--agent-error-border` | `0.0625rem solid rgba(248,113,113,0.3)` | 错误边框 |
|
|
574
|
+
| `--agent-error-border-radius` | `0.5rem` | 错误提示圆角 |
|
|
575
|
+
| `--agent-error-padding` | `0.5rem 0.75rem` | 错误提示内边距 |
|
|
576
|
+
| `--agent-error-icon-color` | `#f87171` | 错误图标颜色 |
|
|
577
|
+
| `--agent-error-text-color` | `#fca5a5` | 错误文本颜色 |
|
|
578
|
+
|
|
579
|
+
#### 执行计划
|
|
580
|
+
|
|
581
|
+
| 变量 | 默认值(深色) | 说明 |
|
|
582
|
+
|---|---|---|
|
|
583
|
+
| `--agent-run-plan-bg` | `rgba(99,102,241,0.06)` | 执行计划背景色 |
|
|
584
|
+
| `--agent-run-plan-border` | `0.0625rem solid rgba(99,102,241,0.15)` | 执行计划边框 |
|
|
585
|
+
| `--agent-run-plan-border-radius` | `0.5rem` | 执行计划圆角 |
|
|
586
|
+
| `--agent-run-plan-text-color` | `#a5b4fc` | 执行计划文本色 |
|
|
587
|
+
| `--agent-run-plan-toggle-color` | `rgba(99,102,241,0.5)` | 展开/折叠图标色 |
|
|
588
|
+
| `--agent-run-plan-icon-color` | `#818cf8` | 执行计划图标色 |
|
|
589
|
+
| `--agent-run-plan-font-size` | `0.8125rem` | 执行计划字号 |
|
|
590
|
+
| `--agent-run-plan-line-height` | `1.5` | 执行计划行高 |
|
|
591
|
+
| `--agent-run-plan-padding` | `0.5rem 0.75rem` | 执行计划内边距 |
|
|
566
592
|
| `--agent-code-block-bg` | `#0d1117` | 代码块背景 |
|
|
567
593
|
| `--agent-table-border` | `#253354` | 表格边框色 |
|
|
568
594
|
| `--agent-table-header-bg` | `#1a2340` | 表头背景 |
|
|
@@ -582,16 +608,33 @@ const chatRef = ref()
|
|
|
582
608
|
流式对话接口返回的 SSE 事件格式:
|
|
583
609
|
|
|
584
610
|
```json
|
|
611
|
+
{ "type": "session", "session_id": 123 }
|
|
585
612
|
{ "type": "status", "content": "正在查询数据..." }
|
|
586
613
|
{ "type": "sql", "content": "SELECT * FROM ..." }
|
|
587
614
|
{ "type": "data", "content": [{"col1": "val1", "col2": 100}] }
|
|
588
615
|
{ "type": "chart_config", "content": { /* ECharts 配置对象 */ }
|
|
589
616
|
{ "type": "sources", "content": [{ "id": "db", "title": "数据库" }] }
|
|
617
|
+
{ "type": "run_plan", "content": "1. 解析用户意图\n2. 查询相关数据..." }
|
|
590
618
|
{ "type": "analysis_chunk", "content": "正在分析..." }
|
|
591
619
|
{ "type": "done", "report_id": 123, "title": "分析报告" }
|
|
592
620
|
{ "type": "error", "message": "分析失败" }
|
|
593
621
|
```
|
|
594
622
|
|
|
623
|
+
### SSE 事件分类说明
|
|
624
|
+
|
|
625
|
+
| 事件类型 | 是否渲染 | 说明 |
|
|
626
|
+
|---|---|---|
|
|
627
|
+
| `session` | 否 | 会话信息,自动保存 session_id |
|
|
628
|
+
| `status` | 是 | 状态提示(如"正在分析意图"),渲染为等待文字+脉冲动画 |
|
|
629
|
+
| `sql` | 可配置 | 生成的 SQL 语句,默认不渲染,通过 `showSql: true` 开启 |
|
|
630
|
+
| `data` | 可配置 | SQL 查询结果数据,默认不渲染为表格,通过 `showData: true` 开启 |
|
|
631
|
+
| `chart_config` | 是 | ECharts 图表配置,使用 useEcharts 渲染(支持暗色主题联动) |
|
|
632
|
+
| `sources` | 是 | 引用来源,渲染为文末编号引用列表,正文中 `[1]` 自动转为上标链接 |
|
|
633
|
+
| `run_plan` | 可配置 | 执行计划/思考过程,默认渲染为可折叠面板,通过 `showRunPlan` 控制 |
|
|
634
|
+
| `analysis_chunk` | 是 | 正文文本流式片段 |
|
|
635
|
+
| `done` | 否 | 流结束标记,携带 report_id 和 title |
|
|
636
|
+
| `error` | 是 | 错误事件,渲染为带左侧色条+警告图标的错误提示 |
|
|
637
|
+
|
|
595
638
|
## 编程式 API
|
|
596
639
|
|
|
597
640
|
除组件方式外,插件也导出了底层 API 和 Store,供高级场景使用:
|
|
@@ -627,6 +670,7 @@ import {
|
|
|
627
670
|
type AgentFullLayoutProps,
|
|
628
671
|
type AgentMobileLayoutProps,
|
|
629
672
|
type ChatMessage,
|
|
673
|
+
type MessageStructuredData,
|
|
630
674
|
type SessionInfo,
|
|
631
675
|
type SourceInfo,
|
|
632
676
|
type StreamCallbacks,
|
|
@@ -647,9 +691,14 @@ setAgentOptions({ apiUrl: 'http://your-server/api/v2' })
|
|
|
647
691
|
const controller = streamChat(
|
|
648
692
|
{ sessionId: 'xxx', query: '你好', userId: 'user123' },
|
|
649
693
|
{
|
|
694
|
+
onSession: (sid) => console.log('会话ID:', sid),
|
|
650
695
|
onStatus: (text) => console.log('状态:', text),
|
|
651
|
-
|
|
696
|
+
onSql: (sql) => console.log('SQL:', sql),
|
|
697
|
+
onData: (data) => console.log('数据:', data),
|
|
652
698
|
onChartConfig: (config) => renderChart(config),
|
|
699
|
+
onSources: (sources) => console.log('来源:', sources),
|
|
700
|
+
onRunPlan: (text) => console.log('执行计划:', text),
|
|
701
|
+
onAnalysisChunk: (chunk) => process.stdout.write(chunk),
|
|
653
702
|
onDone: (reportId, title) => console.log('完成:', title),
|
|
654
703
|
onError: (msg) => console.error('错误:', msg),
|
|
655
704
|
onComplete: () => console.log('流结束'),
|
|
@@ -682,6 +731,10 @@ await chatStore.loadSessions()
|
|
|
682
731
|
await chatStore.newChat()
|
|
683
732
|
chatStore.switchSession('some-session-id')
|
|
684
733
|
chatStore.clearMessages()
|
|
734
|
+
|
|
735
|
+
// 按消息 ID 获取结构化数据(sql/data/chartConfig/sources/runPlan)
|
|
736
|
+
const msgData = chatStore.getMessageData('message-id')
|
|
737
|
+
console.log(msgData?.sql, msgData?.chartConfig)
|
|
685
738
|
```
|
|
686
739
|
|
|
687
740
|
## 开发
|