@gis_victory/ai-chat 1.0.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 ADDED
@@ -0,0 +1,155 @@
1
+ # gis-victory-ai-chat
2
+
3
+ Vue 3 AI 聊天面板组件,支持流式对话、历史记录管理、多技能切换等功能。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install gis-victory-ai-chat
9
+ npm install tdesign-vue-next @tdesign-vue-next/chat
10
+ ```
11
+
12
+ ## 使用
13
+
14
+ ### 基础使用
15
+
16
+ ```vue
17
+ <template>
18
+ <AiChatPanel
19
+ v-model:open="isOpen"
20
+ mode="popup"
21
+ :skills="skills"
22
+ :on-send="handleSend"
23
+ />
24
+ </template>
25
+
26
+ <script setup>
27
+ import { ref } from 'vue'
28
+ import { AiChatPanel } from 'gis-victory-ai-chat'
29
+ import 'gis-victory-ai-chat/style.css'
30
+
31
+ // 需要引入 TDesign 组件库
32
+ import TDesign from 'tdesign-vue-next'
33
+ import '@tdesign-vue-next/chat/es/style/index.css'
34
+
35
+ const isOpen = ref(false)
36
+
37
+ const skills = ref([
38
+ { id: 'general', label: '综合问答', icon: '🤖' },
39
+ { id: 'code', label: '代码助手', icon: '💻' },
40
+ { id: 'document', label: '文档生成', icon: '📄' },
41
+ { id: 'image', label: '图像生成', icon: '🎨' }
42
+ ])
43
+
44
+ const handleSend = async (message, skill, conversationId) => {
45
+ // 调用你的 AI 接口
46
+ const response = await fetch('your-api-endpoint', {
47
+ method: 'POST',
48
+ body: JSON.stringify({ message, skill, conversationId })
49
+ })
50
+ return await response.text()
51
+ }
52
+ </script>
53
+ ```
54
+
55
+ ### 插件式安装
56
+
57
+ ```vue
58
+ <template>
59
+ <AiChatPanel
60
+ mode="page"
61
+ :skills="skills"
62
+ :on-send="handleSend"
63
+ />
64
+ </template>
65
+
66
+ <script setup>
67
+ import { AiChatPanel } from 'gis-victory-ai-chat'
68
+ import 'gis-victory-ai-chat/style.css'
69
+
70
+ // 需要引入 TDesign 组件库
71
+ import TDesign from 'tdesign-vue-next'
72
+ import '@tdesign-vue-next/chat/es/style/index.css'
73
+
74
+ const skills = ref([
75
+ { id: 'general', label: '综合问答' }
76
+ ])
77
+
78
+ const handleSend = async (message, skill, conversationId) => {
79
+ // 你的 AI 接口逻辑
80
+ }
81
+ </script>
82
+ ```
83
+
84
+ ## 依赖
85
+
86
+ - **Vue 3.4.0+** - 核心框架
87
+ - **tdesign-vue-next 1.12.0+** - UI 组件库
88
+ - **@tdesign-vue-next/chat 0.5.2+** - 聊天组件
89
+
90
+ ## Props
91
+
92
+ | 属性 | 类型 | 默认值 | 说明 |
93
+ |------|------|--------|------|
94
+ | `open` | `boolean` | - | 面板是否打开(v-model 绑定) |
95
+ | `mode` | `'popup' \| 'page'` | `'popup'` | 显示模式:弹窗模式或全屏模式 |
96
+ | `position` | `'right-bottom' \| 'left-bottom' \| 'right-top' \| 'left-top'` | `'right-bottom'` | 浮动按钮位置(仅 popup 模式) |
97
+ | `width` | `number \| string` | `500` | 面板宽度 |
98
+ | `height` | `number \| string` | `'auto'` | 面板高度 |
99
+ | `skills` | `Skill[]` | - | 可用的技能列表 |
100
+ | `defaultSkill` | `string` | - | 默认选中的技能 ID |
101
+ | `assistantName` | `string` | `'AI 助手'` | AI 助手名称 |
102
+ | `assistantAvatar` | `string` | - | AI 助手头像 URL |
103
+ | `userAvatar` | `string` | - | 用户头像 URL |
104
+ | `persistent` | `boolean` | `true` | 是否持久化对话记录到 localStorage |
105
+ | `storageKey` | `string` | `'ai-chat-panel'` | localStorage 存储键 |
106
+ | `maxHistory` | `number` | `50` | 最大历史对话数量 |
107
+ | `baseURL` | `string` | - | API 基础 URL |
108
+ | `token` | `string` | - | 认证 token |
109
+ | `appId` | `string` | - | 应用 ID |
110
+
111
+ ## Events
112
+
113
+ | 事件 | 参数 | 说明 |
114
+ |------|------|------|
115
+ | `update:open` | `boolean` | 面板打开/关闭状态变化 |
116
+ | `open` | - | 面板打开时触发 |
117
+ | `close` | - | 面板关闭时触发 |
118
+ | `send` | `{ message, skill, conversationId }` | 发送消息时触发 |
119
+ | `new-chat` | - | 新建对话时触发 |
120
+ | `clear-history` | - | 清除历史记录时触发 |
121
+ | `skill-change` | `skill` | 技能切换时触发 |
122
+
123
+ ## TypeScript 类型
124
+
125
+ ```typescript
126
+ import type { Skill, AiChatPanelProps } from 'gis-victory-ai-chat'
127
+
128
+ interface Skill {
129
+ id: string
130
+ label: string
131
+ icon?: string
132
+ }
133
+ ```
134
+
135
+ ## 注意事项
136
+
137
+ 1. 组件依赖以下包,请确保你的项目已安装:
138
+ - Vue 3.4.0+
139
+ - tdesign-vue-next 1.12.0+
140
+ - @tdesign-vue-next/chat 0.5.2+
141
+
142
+ 2. 需要引入 TDesign 的样式:
143
+ ```javascript
144
+ import '@tdesign-vue-next/chat/es/style/index.css'
145
+ ```
146
+
147
+ 3. 建议使用 `v-model:open` 来控制面板的打开/关闭状态
148
+
149
+ 4. 在 popup 模式下,会显示一个浮动按钮,点击可打开/关闭面板
150
+
151
+ 5. 在 page 模式下,面板会直接全屏显示
152
+
153
+ ## 许可证
154
+
155
+ MIT
@@ -0,0 +1,2 @@
1
+ export { default as AiChatPanel } from './AiChatPanel.vue';
2
+ export * from './types';
@@ -0,0 +1,82 @@
1
+ export type SkillId = 'general' | 'code' | 'doc' | 'image' | 'data' | string;
2
+ export interface Skill {
3
+ id: SkillId;
4
+ label: string;
5
+ icon?: string;
6
+ }
7
+ export interface Message {
8
+ id: string;
9
+ role: 'user' | 'assistant';
10
+ content: string;
11
+ timestamp: number;
12
+ loading?: boolean;
13
+ }
14
+ export interface Conversation {
15
+ id: string;
16
+ title: string;
17
+ skill: SkillId;
18
+ messages: Message[];
19
+ createdAt: number;
20
+ updatedAt: number;
21
+ }
22
+ export interface AiChatPanelProps {
23
+ /** Whether the panel is open (for v-model binding) */
24
+ open?: boolean;
25
+ /** Available skills for switching */
26
+ skills: Skill[];
27
+ /** Whether to show the skill tabs bar */
28
+ showSkills?: boolean;
29
+ /** Allowed skill IDs to display. If set, only skills with matching IDs will be shown */
30
+ allowedSkills?: SkillId[];
31
+ /** Display mode: 'popup' (with floating button) or 'page' (full page mode) */
32
+ mode?: 'popup' | 'page';
33
+ /** Panel position: 'right-bottom' | 'left-bottom' | 'right-top' | 'left-top' (only in popup mode) */
34
+ position?: 'right-bottom' | 'left-bottom' | 'right-top' | 'left-top';
35
+ /** Panel width in pixels */
36
+ width?: number | string;
37
+ /** Panel height in pixels */
38
+ height?: number | string;
39
+ /** AI assistant name */
40
+ assistantName?: string;
41
+ /** Custom avatar URL for AI assistant */
42
+ assistantAvatar?: string;
43
+ /** Custom avatar URL for user */
44
+ userAvatar?: string;
45
+ /** Whether to persist conversation history to localStorage */
46
+ persistent?: boolean;
47
+ /** localStorage key prefix for persistence */
48
+ storageKey?: string;
49
+ /** Maximum history conversations to keep */
50
+ maxHistory?: number;
51
+ /** Whether to show the floating button */
52
+ visible?: boolean;
53
+ /** Send message handler (required for real AI integration) */
54
+ onSend?: (message: string, skill: SkillId, conversationId: string) => Promise<string> | string;
55
+ /** Load history conversations from external source (database/API).
56
+ * Return the full list of valid conversations; locally stored conversations
57
+ * whose IDs are not in the returned list will be removed. */
58
+ onLoadHistory?: () => Promise<Conversation[]> | Conversation[];
59
+ /** API base URL */
60
+ /** Default selected skill id; first skill is used if not specified */
61
+ defaultSkill?: SkillId;
62
+ /** API base URL */
63
+ baseURL?: string;
64
+ /** Auth token */
65
+ token?: string;
66
+ /** Application ID */
67
+ appId?: string;
68
+ }
69
+ export type AiChatPanelEmits = {
70
+ (e: 'open'): void;
71
+ (e: 'close'): void;
72
+ (e: 'send', payload: {
73
+ message: string;
74
+ skill: SkillId;
75
+ conversationId: string;
76
+ }): void;
77
+ (e: 'new-chat'): void;
78
+ (e: 'clear-history'): void;
79
+ (e: 'skill-change', skill: SkillId): void;
80
+ };
81
+ export declare const DEFAULT_SKILLS: Skill[];
82
+ export declare const STORAGE_KEY = "ai-chat-panel";