@kite-copilot/chat-panel 0.2.2 → 0.2.3
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 +103 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,24 +74,115 @@ chat.setCurrentPage('settings');
|
|
|
74
74
|
chat.unmount();
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### Vue.js
|
|
78
|
+
|
|
79
|
+
Create a composable for reusable chat functionality:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
// composables/useKiteChat.ts
|
|
83
|
+
import { ref, onMounted, onUnmounted } from 'vue';
|
|
84
|
+
import { createKiteChat, type KiteChatInstance, type KiteChatConfig } from '@kite-copilot/chat-panel';
|
|
85
|
+
import '@kite-copilot/chat-panel/style.css';
|
|
86
|
+
|
|
87
|
+
export function useKiteChat(config: KiteChatConfig) {
|
|
88
|
+
const chat = ref<KiteChatInstance | null>(null);
|
|
89
|
+
const isOpen = ref(false);
|
|
90
|
+
|
|
91
|
+
onMounted(() => {
|
|
92
|
+
chat.value = createKiteChat({
|
|
93
|
+
...config,
|
|
94
|
+
onNavigate: config.onNavigate,
|
|
95
|
+
});
|
|
96
|
+
chat.value.mount(document.body);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
onUnmounted(() => {
|
|
100
|
+
chat.value?.unmount();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const open = () => {
|
|
104
|
+
chat.value?.open();
|
|
105
|
+
isOpen.value = true;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const close = () => {
|
|
109
|
+
chat.value?.close();
|
|
110
|
+
isOpen.value = false;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const toggle = () => {
|
|
114
|
+
chat.value?.toggle();
|
|
115
|
+
isOpen.value = !isOpen.value;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const setCurrentPage = (page: string) => {
|
|
119
|
+
chat.value?.setCurrentPage(page);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return { isOpen, open, close, toggle, setCurrentPage };
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Use in your App.vue or any component:
|
|
127
|
+
|
|
128
|
+
```vue
|
|
129
|
+
<!-- App.vue -->
|
|
130
|
+
<script setup lang="ts">
|
|
131
|
+
import { useKiteChat } from './composables/useKiteChat';
|
|
132
|
+
import { useRouter } from 'vue-router';
|
|
133
|
+
|
|
134
|
+
const router = useRouter();
|
|
78
135
|
|
|
79
|
-
|
|
80
|
-
<!-- No special container or layout needed! -->
|
|
81
|
-
<script>
|
|
82
|
-
window.KiteChatConfig = {
|
|
136
|
+
const { open, close, toggle, setCurrentPage } = useKiteChat({
|
|
83
137
|
userId: 'user-123',
|
|
84
138
|
orgId: 'org-456',
|
|
85
|
-
agentUrl: 'https://your-api.example.com'
|
|
86
|
-
|
|
139
|
+
agentUrl: 'https://your-api.example.com',
|
|
140
|
+
onNavigate: (page, subtab) => {
|
|
141
|
+
router.push(`/${page}${subtab ? `?tab=${subtab}` : ''}`);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Update context when route changes
|
|
146
|
+
router.afterEach((to) => {
|
|
147
|
+
setCurrentPage(to.name as string);
|
|
148
|
+
});
|
|
87
149
|
</script>
|
|
88
|
-
|
|
150
|
+
|
|
151
|
+
<template>
|
|
152
|
+
<div>
|
|
153
|
+
<button @click="toggle">Toggle Help Panel</button>
|
|
154
|
+
<!-- Your app content -->
|
|
155
|
+
<router-view />
|
|
156
|
+
</div>
|
|
157
|
+
</template>
|
|
89
158
|
```
|
|
90
159
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
160
|
+
Or initialize directly in main.ts for app-wide availability:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
// main.ts
|
|
164
|
+
import { createApp } from 'vue';
|
|
165
|
+
import { createKiteChat } from '@kite-copilot/chat-panel';
|
|
166
|
+
import '@kite-copilot/chat-panel/style.css';
|
|
167
|
+
import App from './App.vue';
|
|
168
|
+
import router from './router';
|
|
169
|
+
|
|
170
|
+
const app = createApp(App);
|
|
171
|
+
app.use(router);
|
|
172
|
+
app.mount('#app');
|
|
173
|
+
|
|
174
|
+
// Initialize chat after Vue app is mounted
|
|
175
|
+
const chat = createKiteChat({
|
|
176
|
+
userId: 'user-123',
|
|
177
|
+
orgId: 'org-456',
|
|
178
|
+
agentUrl: 'https://your-api.example.com',
|
|
179
|
+
onNavigate: (page) => router.push(`/${page}`),
|
|
180
|
+
});
|
|
181
|
+
chat.mount(document.body);
|
|
182
|
+
|
|
183
|
+
// Expose globally if needed
|
|
184
|
+
window.kiteChat = chat;
|
|
185
|
+
```
|
|
95
186
|
|
|
96
187
|
### React Component
|
|
97
188
|
|
|
@@ -265,26 +356,6 @@ function CustomPanel() {
|
|
|
265
356
|
|
|
266
357
|
## Framework Examples
|
|
267
358
|
|
|
268
|
-
### Vue.js
|
|
269
|
-
|
|
270
|
-
```ts
|
|
271
|
-
import { createKiteChat } from '@kite-copilot/chat-panel';
|
|
272
|
-
import '@kite-copilot/chat-panel/style.css';
|
|
273
|
-
|
|
274
|
-
const chat = createKiteChat({
|
|
275
|
-
userId: 'user-123',
|
|
276
|
-
orgId: 'org-456',
|
|
277
|
-
onNavigate: (page) => router.push(`/${page}`),
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// Mount after Vue app is ready
|
|
281
|
-
app.mount('#app');
|
|
282
|
-
chat.mount(document.body);
|
|
283
|
-
|
|
284
|
-
// Open programmatically
|
|
285
|
-
chat.open();
|
|
286
|
-
```
|
|
287
|
-
|
|
288
359
|
### Angular
|
|
289
360
|
|
|
290
361
|
```ts
|