@bdky/chat-pilot-kit-vue3 1.0.4

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.
Files changed (89) hide show
  1. package/README.md +248 -0
  2. package/dist/index.css +1928 -0
  3. package/dist/ky-chat-pilot-kit-vue3.cjs.js +3184 -0
  4. package/dist/ky-chat-pilot-kit-vue3.esm.js +3080 -0
  5. package/dist/libs/chat-pilot-kit-vue3/src/index.d.ts +1 -0
  6. package/dist/libs/chat-pilot-kit-vue3/src/lib/composables/index.d.ts +8 -0
  7. package/dist/libs/chat-pilot-kit-vue3/src/lib/composables/useChatPilotKit.d.ts +4 -0
  8. package/dist/libs/chat-pilot-kit-vue3/src/lib/composables/useChatPilotKitEvents.d.ts +15 -0
  9. package/dist/libs/chat-pilot-kit-vue3/src/lib/composables/useConversations.d.ts +10 -0
  10. package/dist/libs/chat-pilot-kit-vue3/src/lib/composables/useNodeInteraction.d.ts +11 -0
  11. package/dist/libs/chat-pilot-kit-vue3/src/lib/i18n/index.d.ts +5 -0
  12. package/dist/libs/chat-pilot-kit-vue3/src/lib/i18n/translations-context.d.ts +9 -0
  13. package/dist/libs/chat-pilot-kit-vue3/src/lib/i18n/translations.d.ts +10 -0
  14. package/dist/libs/chat-pilot-kit-vue3/src/lib/i18n/zh-CN.d.ts +2 -0
  15. package/dist/libs/chat-pilot-kit-vue3/src/lib/index.d.ts +6 -0
  16. package/dist/libs/chat-pilot-kit-vue3/src/lib/nodeView/VueNodeViewRenderer.d.ts +4 -0
  17. package/dist/libs/chat-pilot-kit-vue3/src/lib/nodeView/defaults/index.d.ts +9 -0
  18. package/dist/libs/chat-pilot-kit-vue3/src/lib/nodeView/defaults/vueExtensions.d.ts +14 -0
  19. package/dist/libs/chat-pilot-kit-vue3/src/lib/nodeView/index.d.ts +6 -0
  20. package/dist/libs/chat-pilot-kit-vue3/src/lib/nodeView/types.d.ts +4 -0
  21. package/dist/libs/chat-pilot-kit-vue3/src/lib/providers/ChatPilotKitProvider.d.ts +8 -0
  22. package/dist/libs/chat-pilot-kit-vue3/src/lib/providers/index.d.ts +2 -0
  23. package/dist/libs/chat-pilot-kit-vue3/src/samples/vue3/components/MockAgentService.d.ts +35 -0
  24. package/dist/libs/chat-pilot-kit-vue3/src/samples/vue3/i18n/translations-context.d.ts +6 -0
  25. package/dist/libs/chat-pilot-kit-vue3/src/samples/vue3/i18n/translations.d.ts +72 -0
  26. package/dist/libs/chat-pilot-kit-vue3/src/samples/vue3/i18n/zh-CN.d.ts +2 -0
  27. package/dist/libs/chat-pilot-kit-vue3/src/samples/vue3/index.d.ts +2 -0
  28. package/dist/libs/chat-pilot-kit-vue3/src/test-setup.d.ts +1 -0
  29. package/dist/static/font/KaTeX_AMS-Regular.ttf +0 -0
  30. package/dist/static/font/KaTeX_AMS-Regular.woff +0 -0
  31. package/dist/static/font/KaTeX_AMS-Regular.woff2 +0 -0
  32. package/dist/static/font/KaTeX_Caligraphic-Bold.ttf +0 -0
  33. package/dist/static/font/KaTeX_Caligraphic-Bold.woff +0 -0
  34. package/dist/static/font/KaTeX_Caligraphic-Bold.woff2 +0 -0
  35. package/dist/static/font/KaTeX_Caligraphic-Regular.ttf +0 -0
  36. package/dist/static/font/KaTeX_Caligraphic-Regular.woff +0 -0
  37. package/dist/static/font/KaTeX_Caligraphic-Regular.woff2 +0 -0
  38. package/dist/static/font/KaTeX_Fraktur-Bold.ttf +0 -0
  39. package/dist/static/font/KaTeX_Fraktur-Bold.woff +0 -0
  40. package/dist/static/font/KaTeX_Fraktur-Bold.woff2 +0 -0
  41. package/dist/static/font/KaTeX_Fraktur-Regular.ttf +0 -0
  42. package/dist/static/font/KaTeX_Fraktur-Regular.woff +0 -0
  43. package/dist/static/font/KaTeX_Fraktur-Regular.woff2 +0 -0
  44. package/dist/static/font/KaTeX_Main-Bold.ttf +0 -0
  45. package/dist/static/font/KaTeX_Main-Bold.woff +0 -0
  46. package/dist/static/font/KaTeX_Main-Bold.woff2 +0 -0
  47. package/dist/static/font/KaTeX_Main-BoldItalic.ttf +0 -0
  48. package/dist/static/font/KaTeX_Main-BoldItalic.woff +0 -0
  49. package/dist/static/font/KaTeX_Main-BoldItalic.woff2 +0 -0
  50. package/dist/static/font/KaTeX_Main-Italic.ttf +0 -0
  51. package/dist/static/font/KaTeX_Main-Italic.woff +0 -0
  52. package/dist/static/font/KaTeX_Main-Italic.woff2 +0 -0
  53. package/dist/static/font/KaTeX_Main-Regular.ttf +0 -0
  54. package/dist/static/font/KaTeX_Main-Regular.woff +0 -0
  55. package/dist/static/font/KaTeX_Main-Regular.woff2 +0 -0
  56. package/dist/static/font/KaTeX_Math-BoldItalic.ttf +0 -0
  57. package/dist/static/font/KaTeX_Math-BoldItalic.woff +0 -0
  58. package/dist/static/font/KaTeX_Math-BoldItalic.woff2 +0 -0
  59. package/dist/static/font/KaTeX_Math-Italic.ttf +0 -0
  60. package/dist/static/font/KaTeX_Math-Italic.woff +0 -0
  61. package/dist/static/font/KaTeX_Math-Italic.woff2 +0 -0
  62. package/dist/static/font/KaTeX_SansSerif-Bold.ttf +0 -0
  63. package/dist/static/font/KaTeX_SansSerif-Bold.woff +0 -0
  64. package/dist/static/font/KaTeX_SansSerif-Bold.woff2 +0 -0
  65. package/dist/static/font/KaTeX_SansSerif-Italic.ttf +0 -0
  66. package/dist/static/font/KaTeX_SansSerif-Italic.woff +0 -0
  67. package/dist/static/font/KaTeX_SansSerif-Italic.woff2 +0 -0
  68. package/dist/static/font/KaTeX_SansSerif-Regular.ttf +0 -0
  69. package/dist/static/font/KaTeX_SansSerif-Regular.woff +0 -0
  70. package/dist/static/font/KaTeX_SansSerif-Regular.woff2 +0 -0
  71. package/dist/static/font/KaTeX_Script-Regular.ttf +0 -0
  72. package/dist/static/font/KaTeX_Script-Regular.woff +0 -0
  73. package/dist/static/font/KaTeX_Script-Regular.woff2 +0 -0
  74. package/dist/static/font/KaTeX_Size1-Regular.ttf +0 -0
  75. package/dist/static/font/KaTeX_Size1-Regular.woff +0 -0
  76. package/dist/static/font/KaTeX_Size1-Regular.woff2 +0 -0
  77. package/dist/static/font/KaTeX_Size2-Regular.ttf +0 -0
  78. package/dist/static/font/KaTeX_Size2-Regular.woff +0 -0
  79. package/dist/static/font/KaTeX_Size2-Regular.woff2 +0 -0
  80. package/dist/static/font/KaTeX_Size3-Regular.ttf +0 -0
  81. package/dist/static/font/KaTeX_Size3-Regular.woff +0 -0
  82. package/dist/static/font/KaTeX_Size3-Regular.woff2 +0 -0
  83. package/dist/static/font/KaTeX_Size4-Regular.ttf +0 -0
  84. package/dist/static/font/KaTeX_Size4-Regular.woff +0 -0
  85. package/dist/static/font/KaTeX_Size4-Regular.woff2 +0 -0
  86. package/dist/static/font/KaTeX_Typewriter-Regular.ttf +0 -0
  87. package/dist/static/font/KaTeX_Typewriter-Regular.woff +0 -0
  88. package/dist/static/font/KaTeX_Typewriter-Regular.woff2 +0 -0
  89. package/package.json +74 -0
package/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # @bdky/chat-pilot-kit-vue3
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@bdky/chat-pilot-kit-vue3.svg)](https://www.npmjs.com/package/@bdky/chat-pilot-kit-vue3)
4
+ [![license](https://img.shields.io/npm/l/@bdky/chat-pilot-kit-vue3.svg)](./LICENSE)
5
+
6
+ `@bdky/chat-pilot-kit` 的 Vue3 适配层,提供 Provider、Composables 和 VueNodeViewRenderer,Markdown 渲染使用 [markstream-vue](https://github.com/markstream/markstream-vue),NodeView 样式采用 GitHub 风格设计。
7
+
8
+ ## 特性
9
+
10
+ - **Provider/Inject 模式** — `provideChatPilotKit` / `injectChatPilotKit`,与 Vue3 依赖注入无缝集成
11
+ - **4 个 Composables** — `useChatPilotKit`、`useChatPilotKitEvents`、`useConversations`、`useNodeInteraction`
12
+ - **VueNodeViewRenderer** — 将 Vue SFC 注册为 NodeView,与 React 版 API 对称
13
+ - **8 个默认 NodeView 组件** — Text、Markdown(流式)、ThinkingBlock、ToolCall、Image、File、Audio、Video
14
+ - **GitHub 风格样式** — 基于 GitHub Primer 色板,支持亮色/暗色模式
15
+
16
+ ## 安装
17
+
18
+ ```bash
19
+ npm install @bdky/chat-pilot-kit-vue3
20
+ # or
21
+ yarn add @bdky/chat-pilot-kit-vue3
22
+ ```
23
+
24
+ 引入样式:
25
+
26
+ ```typescript
27
+ import '@bdky/chat-pilot-kit-vue3/styles.css';
28
+ ```
29
+
30
+ ## 快速开始
31
+
32
+ ### 1. 创建 controller 并注入
33
+
34
+ ```vue
35
+ <!-- App.vue -->
36
+ <script setup lang="ts">
37
+ import {createChatPilotKit, provideChatPilotKit} from '@bdky/chat-pilot-kit-vue3';
38
+ import {MyAgentService} from './services/MyAgentService';
39
+ import ChatApp from './components/ChatApp.vue';
40
+
41
+ const controller = createChatPilotKit({
42
+ agentService: new MyAgentService(),
43
+ });
44
+
45
+ provideChatPilotKit(controller);
46
+ </script>
47
+
48
+ <template>
49
+ <ChatApp />
50
+ </template>
51
+ ```
52
+
53
+ ### 2. 在子组件中使用 Composables
54
+
55
+ ```vue
56
+ <!-- ChatApp.vue -->
57
+ <script setup lang="ts">
58
+ import {
59
+ useChatPilotKit,
60
+ useConversations,
61
+ useChatPilotKitEvents,
62
+ getDefaultVueExtensions,
63
+ } from '@bdky/chat-pilot-kit-vue3';
64
+ import NodeRenderer from '@bdky/chat-pilot-kit-vue3';
65
+
66
+ const {controller} = useChatPilotKit();
67
+ const conversations = useConversations();
68
+
69
+ useChatPilotKitEvents({
70
+ onConversationAdd: (conv) => {
71
+ console.log('新会话', conv.id);
72
+ },
73
+ onNodeAdd: (node) => {
74
+ console.log('新节点', node.id);
75
+ },
76
+ });
77
+
78
+ const extensions = getDefaultVueExtensions();
79
+
80
+ const sendMessage = async () => {
81
+ await controller.conversationService.sendMessage({
82
+ content: 'Hello',
83
+ role: 'user',
84
+ });
85
+ };
86
+ </script>
87
+
88
+ <template>
89
+ <div class="chat-container">
90
+ <div
91
+ v-for="conv in conversations"
92
+ :key="conv.id"
93
+ class="conversation"
94
+ >
95
+ <div
96
+ v-for="node in conv.nodes"
97
+ :key="node.id"
98
+ >
99
+ <NodeRenderer
100
+ :node="node"
101
+ :extensions="extensions"
102
+ />
103
+ </div>
104
+ </div>
105
+ <button @click="sendMessage">发送</button>
106
+ </div>
107
+ </template>
108
+ ```
109
+
110
+ ### 3. 自定义 NodeView
111
+
112
+ ```typescript
113
+ import {VueNodeViewRenderer, MessageExtension} from '@bdky/chat-pilot-kit-vue3';
114
+ import MyCustomView from './MyCustomView.vue';
115
+
116
+ const MyExtension = MessageExtension.extend({
117
+ name: 'my-node',
118
+ addNodeView() {
119
+ return VueNodeViewRenderer(MyCustomView);
120
+ },
121
+ });
122
+ ```
123
+
124
+ `MyCustomView.vue` 接收的 props 类型为 `NodeViewProps`:
125
+
126
+ ```vue
127
+ <script setup lang="ts">
128
+ import type {NodeViewProps} from '@bdky/chat-pilot-kit-vue3';
129
+
130
+ const props = defineProps<NodeViewProps>();
131
+ </script>
132
+ ```
133
+
134
+ ## API 文档
135
+
136
+ ### Provider
137
+
138
+ | 函数 | 说明 |
139
+ |------|------|
140
+ | `provideChatPilotKit(controller)` | 在父组件中注入 controller |
141
+ | `injectChatPilotKit()` | 在子组件中获取注入的 context,未注入时抛错 |
142
+ | `ChatPilotKitProviderKey` | InjectionKey Symbol |
143
+
144
+ ### Composables
145
+
146
+ #### `useChatPilotKit()`
147
+
148
+ 返回 `{ controller }`,controller 为 `createChatPilotKit()` 创建的实例。
149
+
150
+ #### `useChatPilotKitEvents(props)`
151
+
152
+ 监听 emitter 事件,组件卸载时自动清理。
153
+
154
+ | 回调 | 触发时机 |
155
+ |------|----------|
156
+ | `onConversationAdd` | 新会话创建 |
157
+ | `onConversationChange` | 会话状态变更 |
158
+ | `onNodeAdd` | 新节点添加 |
159
+ | `onNodeUpdate` | 节点内容更新 |
160
+ | `onNodeInteraction` | 节点交互事件 |
161
+ | `onHistoryImport` | 历史记录导入 |
162
+ | `onClear` | 会话清空 |
163
+ | `onError` | 错误事件 |
164
+ | `onStart` | 开始生成 |
165
+ | `onStop` | 停止生成 |
166
+ | `onComplete` | 生成完成 |
167
+
168
+ #### `useConversations()`
169
+
170
+ 返回 `ShallowRef<IConversationItem[]>`,响应式跟踪所有会话及其节点。
171
+
172
+ #### `useNodeInteraction(props)`
173
+
174
+ ```typescript
175
+ const {sendCommand} = useNodeInteraction({
176
+ filter: (payload) => payload.nodeId === targetId,
177
+ onInteraction: (payload) => { /* ... */ },
178
+ });
179
+
180
+ // 向节点发送命令
181
+ sendCommand(nodeId, 'copy', {});
182
+ ```
183
+
184
+ ### NodeView
185
+
186
+ | 导出 | 说明 |
187
+ |------|------|
188
+ | `VueNodeViewRenderer(Component)` | 将 Vue SFC 包装为 NodeView factory |
189
+ | `extractVueComponent(factory)` | 从 factory 中提取 Vue 组件 |
190
+ | `NodeRenderer` | 核心渲染组件,自动选择 Vue/DOM 渲染路径 |
191
+ | `DomNodeRenderer` | 非 Vue NodeView 的 DOM 挂载组件 |
192
+
193
+ ### 默认扩展
194
+
195
+ ```typescript
196
+ import {getDefaultVueExtensions} from '@bdky/chat-pilot-kit-vue3';
197
+
198
+ // 获取全部 8 个默认扩展
199
+ const extensions = getDefaultVueExtensions();
200
+ ```
201
+
202
+ 也可单独引用:
203
+
204
+ ```typescript
205
+ import {
206
+ VueTextExtension,
207
+ VueMarkdownExtension,
208
+ VueThinkingBlockExtension,
209
+ VueToolCallExtension,
210
+ VueImageExtension,
211
+ VueFileExtension,
212
+ VueAudioExtension,
213
+ VueVideoExtension,
214
+ } from '@bdky/chat-pilot-kit-vue3';
215
+ ```
216
+
217
+ ## 样式定制
218
+
219
+ 通过 CSS 变量覆盖 GitHub Primer 色板:
220
+
221
+ ```css
222
+ :root {
223
+ --cpk-node-accent: #your-brand-color;
224
+ --cpk-node-surface: #your-surface-color;
225
+ --cpk-node-border: #your-border-color;
226
+ }
227
+ ```
228
+
229
+ 支持 `[data-theme="dark"]` 属性切换暗色模式:
230
+
231
+ ```javascript
232
+ document.documentElement.setAttribute('data-theme', 'dark');
233
+ ```
234
+
235
+ ## 与 React 版对比
236
+
237
+ | 特性 | React 版 (`chat-pilot-kit-react`) | Vue3 版 (`chat-pilot-kit-vue3`) |
238
+ |------|----------------------------------|--------------------------------|
239
+ | Provider | `<ChatPilotKitProvider>` 组件 | `provideChatPilotKit()` 函数 |
240
+ | 获取 context | `useChatPilotKit()` hook | `useChatPilotKit()` composable |
241
+ | 事件监听 | `useChatPilotKitEvents()` hook | `useChatPilotKitEvents()` composable |
242
+ | 会话列表 | `useConversations()` hook | `useConversations()` composable |
243
+ | NodeView 注册 | `ReactNodeViewRenderer` | `VueNodeViewRenderer` |
244
+ | Markdown 渲染 | streamdown | markstream-vue |
245
+
246
+ ## License
247
+
248
+ MIT