cd-aichat 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cd-aichat",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Vue3组件,用于与Dify API进行交互,实现AI聊天功能",
5
5
  "main": "dist/cd-aichat.umd.js",
6
6
  "module": "dist/cd-aichat.es.js",
@@ -8,6 +8,14 @@
8
8
  "dist",
9
9
  "src"
10
10
  ],
11
+ "scripts": {
12
+ "dev": "vite",
13
+ "build": "vite build",
14
+ "preview": "vite preview",
15
+ "test": "vitest",
16
+ "test:ui": "vitest --ui",
17
+ "test:run": "vitest run"
18
+ },
11
19
  "keywords": [
12
20
  "vue",
13
21
  "vue3",
@@ -49,13 +57,5 @@
49
57
  "happy-dom": "^20.0.11",
50
58
  "vite": "^6.0.5",
51
59
  "vitest": "^2.1.9"
52
- },
53
- "scripts": {
54
- "dev": "vite",
55
- "build": "vite build",
56
- "preview": "vite preview",
57
- "test": "vitest",
58
- "test:ui": "vitest --ui",
59
- "test:run": "vitest run"
60
60
  }
61
- }
61
+ }
@@ -205,10 +205,16 @@ class DifyApiService {
205
205
  payload.conversation_id = conversationId;
206
206
  }
207
207
 
208
+ const headers = {
209
+ 'X-Agent-Id': this.agentId
210
+ };
211
+
212
+ if (this.apiKey) {
213
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
214
+ }
215
+
208
216
  const response = await this.client.post(`/chat-messages`, payload, {
209
- headers: {
210
- 'X-Agent-Id': this.agentId
211
- }
217
+ headers
212
218
  });
213
219
 
214
220
  // 更新当前会话 ID
@@ -222,6 +228,8 @@ class DifyApiService {
222
228
  return response.data;
223
229
  } catch (error) {
224
230
  console.error('Error sending message to Dify API:', error);
231
+ console.error('Error details:', error.response?.data);
232
+ console.error('Request payload:', payload);
225
233
  throw error;
226
234
  }
227
235
  }
@@ -240,14 +248,20 @@ class DifyApiService {
240
248
  throw new Error('User ID is required');
241
249
  }
242
250
 
251
+ const headers = {
252
+ 'X-Agent-Id': this.agentId
253
+ };
254
+
255
+ if (this.apiKey) {
256
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
257
+ }
258
+
243
259
  const response = await this.client.get(`/conversations`, {
244
260
  params: {
245
261
  user: userId,
246
262
  limit
247
263
  },
248
- headers: {
249
- 'X-Agent-Id': this.agentId
250
- }
264
+ headers
251
265
  });
252
266
 
253
267
  return response.data;