@cimulate/copilot-sdk 3.12.0 → 3.14.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.
Files changed (33) hide show
  1. package/dist/{bundle.cimulate.copilot-sdk.80adb541.umd.js → bundle.cimulate.copilot-sdk.7dbeb4d0.umd.js} +2 -2
  2. package/dist/{bundle.cimulate.copilot-sdk.0480464d.esm.js.map → bundle.cimulate.copilot-sdk.7dbeb4d0.umd.js.map} +1 -1
  3. package/dist/{bundle.cimulate.copilot-sdk.0480464d.esm.js → bundle.cimulate.copilot-sdk.a60898e7.esm.js} +2 -2
  4. package/dist/{bundle.cimulate.copilot-sdk.e8d315fa.cjs.js.map → bundle.cimulate.copilot-sdk.a60898e7.esm.js.map} +1 -1
  5. package/dist/{bundle.cimulate.copilot-sdk.e8d315fa.cjs.js → bundle.cimulate.copilot-sdk.ff5873e3.cjs.js} +2 -2
  6. package/dist/{bundle.cimulate.copilot-sdk.80adb541.umd.js.map → bundle.cimulate.copilot-sdk.ff5873e3.cjs.js.map} +1 -1
  7. package/dist/index.cjs.js +1 -1
  8. package/dist/index.cjs.js.map +1 -1
  9. package/dist/index.esm.js +1 -1
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.umd.js +1 -1
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/model/AskCim.d.ts +1 -0
  14. package/dist/types/model/AskCimSuggestions.d.ts +3 -0
  15. package/dist/types/model/CopilotBrowse.d.ts +1 -0
  16. package/dist/types/model/CopilotBrowseSuggestions.d.ts +5 -0
  17. package/dist/types/model/CopilotSearch.d.ts +1 -0
  18. package/dist/types/model/CopilotSearchSuggestions.d.ts +5 -0
  19. package/dist/types/model/ProductView.d.ts +1 -0
  20. package/dist/types/model/ProductViewSuggestions.d.ts +4 -0
  21. package/dist/types/model/index.d.ts +4 -0
  22. package/examples/getConversations.ts +58 -0
  23. package/package.json +4 -1
  24. package/src/model/AskCim.ts +1 -0
  25. package/src/model/AskCimSuggestions.ts +5 -0
  26. package/src/model/CopilotBrowse.ts +1 -0
  27. package/src/model/CopilotBrowseSuggestions.ts +5 -0
  28. package/src/model/CopilotSearch.ts +1 -0
  29. package/src/model/CopilotSearchSuggestions.ts +5 -0
  30. package/src/model/ProductView.ts +1 -0
  31. package/src/model/ProductViewSuggestions.ts +5 -0
  32. package/src/model/index.ts +4 -0
  33. package/src/parser.ts +17 -7
@@ -0,0 +1,5 @@
1
+ import { BrowseParams } from './BrowseParams';
2
+ interface CopilotBrowseSuggestions {
3
+ browseParams: BrowseParams;
4
+ }
5
+ export { CopilotBrowseSuggestions };
@@ -4,5 +4,6 @@ interface CopilotSearch {
4
4
  searchParams: SearchParams;
5
5
  userPrompt?: string;
6
6
  attachments?: Attachments;
7
+ clientContext?: Record<string, string | number>;
7
8
  }
8
9
  export { CopilotSearch };
@@ -0,0 +1,5 @@
1
+ import { SearchParams } from './SearchParams';
2
+ interface CopilotSearchSuggestions {
3
+ searchParams: SearchParams;
4
+ }
5
+ export { CopilotSearchSuggestions };
@@ -4,5 +4,6 @@ interface ProductView {
4
4
  pdpLink?: string;
5
5
  userPrompt?: string;
6
6
  attachments?: Attachments;
7
+ clientContext?: Record<string, string | number>;
7
8
  }
8
9
  export { ProductView };
@@ -0,0 +1,4 @@
1
+ interface ProductViewSuggestions {
2
+ productId: string;
3
+ }
4
+ export { ProductViewSuggestions };
@@ -1,5 +1,6 @@
1
1
  export * from './AskCim';
2
2
  export * from './AskCimAck';
3
+ export * from './AskCimSuggestions';
3
4
  export * from './Attachments';
4
5
  export * from './BrowseParams';
5
6
  export * from './Cancel';
@@ -18,11 +19,13 @@ export * from './CopilotAPIEvent';
18
19
  export * from './CopilotBrowse';
19
20
  export * from './CopilotBrowseAck';
20
21
  export * from './CopilotBrowseSuggestion';
22
+ export * from './CopilotBrowseSuggestions';
21
23
  export * from './CopilotError';
22
24
  export * from './CopilotEvent';
23
25
  export * from './CopilotSearch';
24
26
  export * from './CopilotSearchAck';
25
27
  export * from './CopilotSearchSuggestion';
28
+ export * from './CopilotSearchSuggestions';
26
29
  export * from './customization';
27
30
  export * from './DisplayProducts';
28
31
  export * from './Done';
@@ -38,6 +41,7 @@ export * from './PartialInquiry';
38
41
  export * from './ProductView';
39
42
  export * from './ProductViewAck';
40
43
  export * from './ProductViewSuggestion';
44
+ export * from './ProductViewSuggestions';
41
45
  export * from './Progress';
42
46
  export * from './ProgressToolKwargs';
43
47
  export * from './RefinedBrowse';
@@ -0,0 +1,58 @@
1
+ import { CimulateCopilot } from "@cimulate/copilot-sdk";
2
+
3
+
4
+ async function main() {
5
+ const sessionId = "EXISTING_SESSION_ID";
6
+ const customerId = "CustomerId";
7
+ const copilot = new CimulateCopilot({
8
+ apiKey: "API_KEY",
9
+ // Alternatively, a JWT token of the form `Bearer {token}` can be used for authentication.
10
+ // apiToken: "token123",
11
+ baseUrl: "https://qa.copilot.search.cimulate.ai",
12
+ // Optionally provide a session ID to reuse an existing session
13
+ socketOptions: {
14
+ auth: {
15
+ ["x-cimulate-copilot-session-id"]: sessionId
16
+ }
17
+ }
18
+ });
19
+
20
+ // Register handlers.
21
+ const connectAckHandler = copilot.on("connect_ack", function connectAck(event) {
22
+ console.log("Connect Ack: ", event);
23
+ });
24
+
25
+ const errorHandler = copilot.on("error", function errorEvent(event) {
26
+ console.error("Error received: ", event);
27
+ });
28
+
29
+ const connectErrorHandler = copilot.on("connect_error", function errorEvent(error) {
30
+ console.error("Error message received: ", error.message);
31
+ });
32
+
33
+ console.log("Establish a new connection");
34
+ // copilot.connect();
35
+ copilot.reconnect();
36
+
37
+ const conversations = await copilot.getConversationEvents({
38
+ conversationId: `conversation:${customerId}:${sessionId}:0`
39
+ });
40
+ // console.log("Conversations: ", conversations);
41
+
42
+ console.log("Disconnect");
43
+ copilot.disconnect();
44
+
45
+ console.log("De-register handler");
46
+ copilot.off("connect_ack", connectAckHandler);
47
+ copilot.off("error", errorHandler);
48
+ copilot.off("connect_error", connectErrorHandler);
49
+
50
+ console.log("Refined Search and Display Products events: ");
51
+ // Iterate over the events and print the event name and the data
52
+ for (const event of conversations.filter((event) => event.name === "refined_search" || event.name === "display_products")) {
53
+ console.log(JSON.stringify(event, null, 2));
54
+ }
55
+
56
+ }
57
+
58
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cimulate/copilot-sdk",
3
- "version": "3.12.0",
3
+ "version": "3.14.0",
4
4
  "description": "A lightweight API client SDK for Cimulate Copilot",
5
5
  "files": [
6
6
  "dist/**",
@@ -53,5 +53,8 @@
53
53
  "webpack": "^5.97.1",
54
54
  "webpack-cli": "^6.0.1",
55
55
  "webpack-node-externals": "^3.0.0"
56
+ },
57
+ "overrides": {
58
+ "brace-expansion": "~2.0.2"
56
59
  }
57
60
  }
@@ -2,5 +2,6 @@ import { Attachments } from './Attachments';
2
2
  interface AskCim {
3
3
  userPrompt: string;
4
4
  attachments?: Attachments;
5
+ clientContext?: Record<string, string | number>;
5
6
  }
6
7
  export { AskCim };
@@ -0,0 +1,5 @@
1
+
2
+ interface AskCimSuggestions {
3
+
4
+ }
5
+ export { AskCimSuggestions };
@@ -4,5 +4,6 @@ interface CopilotBrowse {
4
4
  browseParams: BrowseParams;
5
5
  userPrompt?: string;
6
6
  attachments?: Attachments;
7
+ clientContext?: Record<string, string | number>;
7
8
  }
8
9
  export { CopilotBrowse };
@@ -0,0 +1,5 @@
1
+ import { BrowseParams } from './BrowseParams';
2
+ interface CopilotBrowseSuggestions {
3
+ browseParams: BrowseParams;
4
+ }
5
+ export { CopilotBrowseSuggestions };
@@ -4,5 +4,6 @@ interface CopilotSearch {
4
4
  searchParams: SearchParams;
5
5
  userPrompt?: string;
6
6
  attachments?: Attachments;
7
+ clientContext?: Record<string, string | number>;
7
8
  }
8
9
  export { CopilotSearch };
@@ -0,0 +1,5 @@
1
+ import { SearchParams } from './SearchParams';
2
+ interface CopilotSearchSuggestions {
3
+ searchParams: SearchParams;
4
+ }
5
+ export { CopilotSearchSuggestions };
@@ -4,5 +4,6 @@ interface ProductView {
4
4
  pdpLink?: string;
5
5
  userPrompt?: string;
6
6
  attachments?: Attachments;
7
+ clientContext?: Record<string, string | number>;
7
8
  }
8
9
  export { ProductView };
@@ -0,0 +1,5 @@
1
+
2
+ interface ProductViewSuggestions {
3
+ productId: string;
4
+ }
5
+ export { ProductViewSuggestions };
@@ -1,5 +1,6 @@
1
1
  export * from './AskCim';
2
2
  export * from './AskCimAck';
3
+ export * from './AskCimSuggestions';
3
4
  export * from './Attachments';
4
5
  export * from './BrowseParams';
5
6
  export * from './Cancel';
@@ -18,11 +19,13 @@ export * from './CopilotAPIEvent';
18
19
  export * from './CopilotBrowse';
19
20
  export * from './CopilotBrowseAck';
20
21
  export * from './CopilotBrowseSuggestion';
22
+ export * from './CopilotBrowseSuggestions';
21
23
  export * from './CopilotError';
22
24
  export * from './CopilotEvent';
23
25
  export * from './CopilotSearch';
24
26
  export * from './CopilotSearchAck';
25
27
  export * from './CopilotSearchSuggestion';
28
+ export * from './CopilotSearchSuggestions';
26
29
  export * from './customization';
27
30
  export * from './DisplayProducts';
28
31
  export * from './Done';
@@ -38,6 +41,7 @@ export * from './PartialInquiry';
38
41
  export * from './ProductView';
39
42
  export * from './ProductViewAck';
40
43
  export * from './ProductViewSuggestion';
44
+ export * from './ProductViewSuggestions';
41
45
  export * from './Progress';
42
46
  export * from './ProgressToolKwargs';
43
47
  export * from './RefinedBrowse';
package/src/parser.ts CHANGED
@@ -18,13 +18,23 @@ class SnakeCaseEncoder extends Encoder {
18
18
 
19
19
  class SnakeCaseDecoder extends Decoder {
20
20
  constructor() {
21
- super((key, value) =>
22
- key == "" && Array.isArray(value)
23
- ? value.map((value) =>
24
- value instanceof Object ? decode(value) : value
25
- )
26
- : value
27
- );
21
+ super((key, value) => {
22
+ // Handle top-level arrays (key == "" means root level)
23
+ if (key == "" && Array.isArray(value)) {
24
+ return value.map((item) => {
25
+ // If item is an array (nested array case like [[{...}]])
26
+ if (Array.isArray(item)) {
27
+ // Process each event in the inner array
28
+ return item.map((event) =>
29
+ event instanceof Object ? decode(event) : event
30
+ );
31
+ }
32
+ // If item is an object (single array case like [{...}])
33
+ return item instanceof Object ? decode(item) : item;
34
+ });
35
+ }
36
+ return value;
37
+ });
28
38
  }
29
39
  }
30
40