@astermind/cybernetic-chatbot-client 2.2.3 → 2.2.9

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.
@@ -6,6 +6,22 @@
6
6
 
7
7
  // src/ApiClient.ts
8
8
  // HTTP client for AsterMind backend API
9
+ /**
10
+ * Map backend source format to client Source interface
11
+ */
12
+ function mapSource(raw) {
13
+ return {
14
+ title: raw.title,
15
+ snippet: raw.content,
16
+ relevance: raw.score,
17
+ documentId: raw.documentId,
18
+ fullContent: raw.fullContent,
19
+ downloadUrl: raw.downloadUrl,
20
+ documentName: raw.documentName,
21
+ sourceType: raw.sourceType,
22
+ chunkId: raw.chunkId
23
+ };
24
+ }
9
25
  /**
10
26
  * HTTP/SSE client for AsterMind backend
11
27
  */
@@ -34,7 +50,12 @@
34
50
  const error = await response.json().catch(() => ({}));
35
51
  throw new Error(error.message || `HTTP ${response.status}: ${response.statusText}`);
36
52
  }
37
- return response.json();
53
+ const data = await response.json();
54
+ // Map backend source format to client Source interface
55
+ return {
56
+ ...data,
57
+ sources: (data.sources || []).map(mapSource)
58
+ };
38
59
  }
39
60
  /**
40
61
  * Send chat message with streaming response via SSE
@@ -86,8 +107,8 @@
86
107
  options.onToken?.(data.text);
87
108
  }
88
109
  else if (data.sources !== undefined) {
89
- // Sources event
90
- sources = data.sources;
110
+ // Sources event - map backend format to client format
111
+ sources = (data.sources || []).map(mapSource);
91
112
  options.onSources?.(sources);
92
113
  }
93
114
  else if (data.sessionId !== undefined) {