@cimulate/copilot-sdk 3.11.0 → 3.13.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.
- package/dist/{bundle.cimulate.copilot-sdk.80adb541.umd.js → bundle.cimulate.copilot-sdk.7dbeb4d0.umd.js} +2 -2
- package/dist/{bundle.cimulate.copilot-sdk.0480464d.esm.js.map → bundle.cimulate.copilot-sdk.7dbeb4d0.umd.js.map} +1 -1
- package/dist/{bundle.cimulate.copilot-sdk.0480464d.esm.js → bundle.cimulate.copilot-sdk.a60898e7.esm.js} +2 -2
- package/dist/{bundle.cimulate.copilot-sdk.e8d315fa.cjs.js.map → bundle.cimulate.copilot-sdk.a60898e7.esm.js.map} +1 -1
- package/dist/{bundle.cimulate.copilot-sdk.e8d315fa.cjs.js → bundle.cimulate.copilot-sdk.ff5873e3.cjs.js} +2 -2
- package/dist/{bundle.cimulate.copilot-sdk.80adb541.umd.js.map → bundle.cimulate.copilot-sdk.ff5873e3.cjs.js.map} +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/model/AskCim.d.ts +2 -0
- package/dist/types/model/Attachments.d.ts +4 -0
- package/dist/types/model/CopilotApiAck.d.ts +1 -1
- package/dist/types/model/CopilotBrowse.d.ts +2 -0
- package/dist/types/model/CopilotSearch.d.ts +2 -0
- package/dist/types/model/ProductView.d.ts +2 -0
- package/dist/types/model/index.d.ts +1 -0
- package/examples/getConversations.ts +58 -0
- package/package.json +1 -1
- package/src/model/AskCim.ts +2 -1
- package/src/model/Attachments.ts +5 -0
- package/src/model/CopilotApiAck.ts +1 -1
- package/src/model/CopilotBrowse.ts +2 -0
- package/src/model/CopilotSearch.ts +2 -0
- package/src/model/ProductView.ts +2 -1
- package/src/model/index.ts +1 -0
- package/src/parser.ts +17 -7
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
This not generated automatically by the generate model script.
|
|
3
3
|
For any new event, manually create an entry here.
|
|
4
4
|
*/
|
|
5
|
+
import { AskCimAck } from "./AskCimAck";
|
|
5
6
|
import { CancelAck } from "./CancelAck";
|
|
6
7
|
import { ConversationResetAck } from "./ConversationResetAck";
|
|
7
8
|
import { CopilotBrowseAck } from "./CopilotBrowseAck";
|
|
@@ -9,5 +10,4 @@ import { CopilotError } from "./CopilotError";
|
|
|
9
10
|
import { CopilotSearchAck } from "./CopilotSearchAck";
|
|
10
11
|
import { FacetedNavigationAck } from "./FacetedNavigationAck";
|
|
11
12
|
import { ProductViewAck } from "./ProductViewAck";
|
|
12
|
-
import { AskCimAck } from "./AskCimAck";
|
|
13
13
|
export type CopilotAPIAck = AskCimAck | CancelAck | CopilotBrowseAck | CopilotSearchAck | ConversationResetAck | FacetedNavigationAck | ProductViewAck | CopilotError;
|
|
@@ -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
package/src/model/AskCim.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
This not generated automatically by the generate model script.
|
|
3
3
|
For any new event, manually create an entry here.
|
|
4
4
|
*/
|
|
5
|
+
import { AskCimAck } from "./AskCimAck";
|
|
5
6
|
import { CancelAck } from "./CancelAck";
|
|
6
7
|
import { ConversationResetAck } from "./ConversationResetAck";
|
|
7
8
|
import { CopilotBrowseAck } from "./CopilotBrowseAck";
|
|
@@ -9,7 +10,6 @@ import { CopilotError } from "./CopilotError";
|
|
|
9
10
|
import { CopilotSearchAck } from "./CopilotSearchAck";
|
|
10
11
|
import { FacetedNavigationAck } from "./FacetedNavigationAck";
|
|
11
12
|
import { ProductViewAck } from "./ProductViewAck";
|
|
12
|
-
import { AskCimAck } from "./AskCimAck";
|
|
13
13
|
|
|
14
14
|
export type CopilotAPIAck =
|
|
15
15
|
| AskCimAck
|
package/src/model/ProductView.ts
CHANGED
package/src/model/index.ts
CHANGED
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 == ""
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
|
|
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
|
|