@cimulate/copilot-sdk 1.1.2 → 1.2.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/README.md +15 -0
- package/dist/bundle.cimulate.copilot-sdk.099d19fa.umd.js +2 -0
- package/dist/bundle.cimulate.copilot-sdk.099d19fa.umd.js.map +1 -0
- package/dist/bundle.cimulate.copilot-sdk.5716b677.cjs.js +2 -0
- package/dist/bundle.cimulate.copilot-sdk.5716b677.cjs.js.map +1 -0
- package/dist/bundle.cimulate.copilot-sdk.64883fd2.esm.js +2 -0
- package/dist/bundle.cimulate.copilot-sdk.64883fd2.esm.js.map +1 -0
- 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/copilot.d.ts +17 -17
- package/dist/types/model/CommonFields.d.ts +0 -1
- package/dist/types/model/CommonMetadata.d.ts +7 -0
- package/dist/types/model/CommonRequiredFields.d.ts +0 -1
- package/dist/types/model/ConnectAck.d.ts +1 -1
- package/dist/types/model/{ConnectionAcknowledgmentMessageFields.d.ts → ConnectAckMessageFields.d.ts} +3 -2
- package/dist/types/model/CopilotEvent.d.ts +20 -0
- package/dist/types/model/CopilotSearch.d.ts +2 -2
- package/dist/types/model/CopilotSearchSuggestion.d.ts +7 -0
- package/dist/types/model/DisplayProducts.d.ts +4 -3
- package/dist/types/model/DisplayProductsMessageFields.d.ts +4 -2
- package/dist/types/model/Done.d.ts +1 -1
- package/dist/types/model/DoneMessageFields.d.ts +4 -0
- package/dist/types/model/Error.d.ts +1 -1
- package/dist/types/model/ErrorMessageFields.d.ts +1 -0
- package/dist/types/model/EventAck.d.ts +11 -5
- package/dist/types/model/EventAckMessageFields.d.ts +10 -0
- package/dist/types/model/EventAckNames.d.ts +6 -0
- package/dist/types/model/FacetedNavigation.d.ts +2 -2
- package/dist/types/model/FacetedNavigationSuggestion.d.ts +7 -0
- package/dist/types/model/FollowUp.d.ts +4 -3
- package/dist/types/model/FollowUpMessageFields.d.ts +7 -0
- package/dist/types/model/Inquiry.d.ts +1 -1
- package/dist/types/model/InquiryMessageFields.d.ts +4 -0
- package/dist/types/model/PartialInquiry.d.ts +1 -1
- package/dist/types/model/PartialInquiryMessageFields.d.ts +1 -0
- package/dist/types/model/RefinedSearch.d.ts +6 -5
- package/dist/types/model/RefinedSearchMessageFields.d.ts +6 -4
- package/dist/types/model/ReturnedFields.d.ts +2 -0
- package/dist/types/model/Root.d.ts +17 -9
- package/dist/types/model/SearchParams.d.ts +5 -0
- package/dist/types/model/SessionData.d.ts +5 -4
- package/dist/types/model/SessionEventStatusReply.d.ts +0 -1
- package/dist/types/model/SessionInformation.d.ts +3 -3
- package/dist/types/model/WorkflowMetadata.d.ts +5 -0
- package/dist/types/model/index.d.ts +14 -8
- package/package.json +6 -4
- package/rollup.config.js +1 -1
- package/src/copilot.ts +49 -25
- package/src/model/CommonFields.ts +0 -1
- package/src/model/CommonMetadata.ts +7 -0
- package/src/model/CommonRequiredFields.ts +0 -1
- package/src/model/ConnectAck.ts +1 -1
- package/src/model/{ConnectionAcknowledgmentMessageFields.ts → ConnectAckMessageFields.ts} +3 -2
- package/src/model/CopilotEvent.ts +20 -0
- package/src/model/CopilotSearch.ts +2 -2
- package/src/model/CopilotSearchSuggestion.ts +7 -0
- package/src/model/DisplayProducts.ts +4 -4
- package/src/model/DisplayProductsMessageFields.ts +4 -3
- package/src/model/Done.ts +1 -1
- package/src/model/DoneMessageFields.ts +5 -0
- package/src/model/Error.ts +1 -1
- package/src/model/ErrorMessageFields.ts +1 -0
- package/src/model/EventAck.ts +13 -5
- package/src/model/EventAckMessageFields.ts +10 -0
- package/src/model/EventAckNames.ts +7 -0
- package/src/model/FacetedNavigation.ts +2 -2
- package/src/model/FacetedNavigationSuggestion.ts +7 -0
- package/src/model/FollowUp.ts +4 -3
- package/src/model/FollowUpMessageFields.ts +7 -0
- package/src/model/Inquiry.ts +1 -1
- package/src/model/InquiryMessageFields.ts +5 -0
- package/src/model/PartialInquiry.ts +1 -1
- package/src/model/PartialInquiryMessageFields.ts +1 -0
- package/src/model/RefinedSearch.ts +6 -5
- package/src/model/RefinedSearchMessageFields.ts +6 -4
- package/src/model/ReturnedFields.ts +4 -0
- package/src/model/Root.ts +17 -9
- package/src/model/SearchParams.ts +6 -0
- package/src/model/SessionData.ts +5 -4
- package/src/model/SessionEventStatusReply.ts +0 -1
- package/src/model/SessionInformation.ts +3 -3
- package/src/model/WorkflowMetadata.ts +6 -0
- package/src/model/index.ts +14 -8
- package/tsconfig.json +2 -1
- package/dist/bundle.cimulate.copilot-sdk.2115a6a5.esm.js +0 -2
- package/dist/bundle.cimulate.copilot-sdk.2115a6a5.esm.js.map +0 -1
- package/dist/bundle.cimulate.copilot-sdk.4bdff942.cjs.js +0 -2
- package/dist/bundle.cimulate.copilot-sdk.4bdff942.cjs.js.map +0 -1
- package/dist/bundle.cimulate.copilot-sdk.83e04b89.umd.js +0 -2
- package/dist/bundle.cimulate.copilot-sdk.83e04b89.umd.js.map +0 -1
- package/dist/types/model/EventAcknowledgmentMessageFields.d.ts +0 -6
- package/dist/types/model/FollowMinusUpMessageFields.d.ts +0 -5
- package/dist/types/model/ReservedEvent.d.ts +0 -10
- package/dist/types/model/SearchParameters.d.ts +0 -5
- package/dist/types/model/SessionEventInformationReply.d.ts +0 -5
- package/dist/types/model/Suggestion.d.ts +0 -6
- package/src/model/EventAcknowledgmentMessageFields.ts +0 -6
- package/src/model/FollowMinusUpMessageFields.ts +0 -5
- package/src/model/ReservedEvent.ts +0 -11
- package/src/model/SearchParameters.ts +0 -6
- package/src/model/SessionEventInformationReply.ts +0 -6
- package/src/model/Suggestion.ts +0 -7
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { CopilotSearch } from './CopilotSearch';
|
|
2
|
-
|
|
2
|
+
import { FacetedNavigation } from './FacetedNavigation';
|
|
3
|
+
import { Cancel } from './Cancel';
|
|
4
|
+
import { EventAckNames } from './EventAckNames';
|
|
5
|
+
type EventRequestMap = {
|
|
6
|
+
copilot_search_ack: CopilotSearch;
|
|
7
|
+
faceted_navigation_ack: FacetedNavigation;
|
|
8
|
+
cancel_ack: Cancel;
|
|
9
|
+
};
|
|
10
|
+
interface EventAck<T extends EventAckNames = EventAckNames> {
|
|
3
11
|
session_id: string;
|
|
4
12
|
event_id: string;
|
|
5
|
-
event_name: string;
|
|
6
13
|
timestamp: string;
|
|
7
|
-
event_source_id: string;
|
|
8
|
-
message: string;
|
|
9
14
|
status: string;
|
|
10
|
-
request:
|
|
15
|
+
request: EventRequestMap[T];
|
|
16
|
+
event_name: T;
|
|
11
17
|
}
|
|
12
18
|
export { EventAck };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CopilotSearch } from './CopilotSearch';
|
|
2
|
+
import { FacetedNavigation } from './FacetedNavigation';
|
|
3
|
+
import { Cancel } from './Cancel';
|
|
4
|
+
import { EventAckNames } from './EventAckNames';
|
|
5
|
+
interface EventAckMessageFields {
|
|
6
|
+
status: string;
|
|
7
|
+
request: CopilotSearch | FacetedNavigation | Cancel;
|
|
8
|
+
event_name: EventAckNames;
|
|
9
|
+
}
|
|
10
|
+
export { EventAckMessageFields };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CopilotSearchSuggestion } from './CopilotSearchSuggestion';
|
|
2
|
+
import { FacetedNavigationSuggestion } from './FacetedNavigationSuggestion';
|
|
2
3
|
interface FollowUp {
|
|
3
4
|
session_id: string;
|
|
4
5
|
event_id: string;
|
|
5
|
-
event_name: string;
|
|
6
6
|
timestamp: string;
|
|
7
7
|
event_source_id: string;
|
|
8
8
|
message: string;
|
|
9
|
-
suggestions:
|
|
9
|
+
suggestions: (CopilotSearchSuggestion | FacetedNavigationSuggestion)[];
|
|
10
|
+
event_name: 'follow_up';
|
|
10
11
|
}
|
|
11
12
|
export { FollowUp };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CopilotSearchSuggestion } from './CopilotSearchSuggestion';
|
|
2
|
+
import { FacetedNavigationSuggestion } from './FacetedNavigationSuggestion';
|
|
3
|
+
interface FollowUpMessageFields {
|
|
4
|
+
suggestions: (CopilotSearchSuggestion | FacetedNavigationSuggestion)[];
|
|
5
|
+
event_name: 'follow_up';
|
|
6
|
+
}
|
|
7
|
+
export { FollowUpMessageFields };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
interface PartialInquiry {
|
|
2
2
|
session_id: string;
|
|
3
3
|
event_id: string;
|
|
4
|
-
event_name: string;
|
|
5
4
|
timestamp: string;
|
|
6
5
|
event_source_id: string;
|
|
7
6
|
message: string;
|
|
8
7
|
inquiry_event_id: string;
|
|
9
8
|
index: number;
|
|
9
|
+
event_name: 'partial_inquiry';
|
|
10
10
|
}
|
|
11
11
|
export { PartialInquiry };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SearchParams } from './SearchParams';
|
|
2
2
|
import { Facet } from './Facet';
|
|
3
|
-
|
|
3
|
+
import type { ReturnedFields } from './ReturnedFields';
|
|
4
|
+
interface RefinedSearch<T extends object = ReturnedFields> {
|
|
4
5
|
session_id: string;
|
|
5
6
|
event_id: string;
|
|
6
|
-
event_name: string;
|
|
7
7
|
timestamp: string;
|
|
8
8
|
event_source_id: string;
|
|
9
9
|
message: string;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
event_name: 'refined_search';
|
|
11
|
+
search_params: SearchParams;
|
|
12
|
+
hits?: T[];
|
|
12
13
|
total_hits?: number;
|
|
13
14
|
facets?: Facet[];
|
|
14
15
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SearchParams } from './SearchParams';
|
|
2
2
|
import { Facet } from './Facet';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type { ReturnedFields } from './ReturnedFields';
|
|
4
|
+
interface RefinedSearchMessageFields<T extends object = ReturnedFields> {
|
|
5
|
+
event_name: 'refined_search';
|
|
6
|
+
search_params: SearchParams;
|
|
7
|
+
hits?: T[];
|
|
6
8
|
total_hits?: number;
|
|
7
9
|
facets?: Facet[];
|
|
8
10
|
}
|
|
@@ -1,54 +1,62 @@
|
|
|
1
1
|
import { CommonRequiredFields } from './CommonRequiredFields';
|
|
2
2
|
import { CommonFields } from './CommonFields';
|
|
3
|
+
import { CommonMetadata } from './CommonMetadata';
|
|
3
4
|
import { ConnectAckMetadata } from './ConnectAckMetadata';
|
|
4
5
|
import { ConnectAck } from './ConnectAck';
|
|
5
|
-
import {
|
|
6
|
+
import { SearchParams } from './SearchParams';
|
|
6
7
|
import { FacetValue } from './FacetValue';
|
|
7
8
|
import { Facet } from './Facet';
|
|
8
9
|
import { CopilotSearch } from './CopilotSearch';
|
|
9
10
|
import { FacetedNavigation } from './FacetedNavigation';
|
|
11
|
+
import { EventAckNames } from './EventAckNames';
|
|
10
12
|
import { EventAck } from './EventAck';
|
|
11
13
|
import { RefinedSearch } from './RefinedSearch';
|
|
12
14
|
import { DisplayProducts } from './DisplayProducts';
|
|
13
|
-
import {
|
|
15
|
+
import { CopilotSearchSuggestion } from './CopilotSearchSuggestion';
|
|
16
|
+
import { FacetedNavigationSuggestion } from './FacetedNavigationSuggestion';
|
|
14
17
|
import { FollowUp } from './FollowUp';
|
|
15
18
|
import { PartialInquiry } from './PartialInquiry';
|
|
16
19
|
import { Inquiry } from './Inquiry';
|
|
17
20
|
import { Done } from './Done';
|
|
18
21
|
import { Error } from './Error';
|
|
19
|
-
import {
|
|
22
|
+
import { CopilotEvent } from './CopilotEvent';
|
|
20
23
|
import { SessionData } from './SessionData';
|
|
21
24
|
import { SessionInformation } from './SessionInformation';
|
|
22
|
-
import { SessionEventInformationReply } from './SessionEventInformationReply';
|
|
23
25
|
import { SessionEventStatusReply } from './SessionEventStatusReply';
|
|
24
26
|
import { Cancel } from './Cancel';
|
|
27
|
+
import type { ReturnedFields } from './ReturnedFields';
|
|
25
28
|
interface Root {
|
|
26
29
|
common_fields?: CommonRequiredFields;
|
|
27
30
|
common_event_fields?: CommonFields;
|
|
31
|
+
common_metadata?: CommonMetadata;
|
|
28
32
|
connect_ack_metadata?: ConnectAckMetadata;
|
|
29
33
|
connect_ack?: ConnectAck;
|
|
30
|
-
search_params?:
|
|
34
|
+
search_params?: SearchParams;
|
|
31
35
|
facet_value?: FacetValue;
|
|
32
36
|
facets?: Facet[];
|
|
33
37
|
copilot_search?: CopilotSearch;
|
|
34
38
|
faceted_navigation?: FacetedNavigation;
|
|
39
|
+
event_ack_names?: EventAckNames;
|
|
35
40
|
event_ack?: EventAck;
|
|
36
41
|
refined_search?: RefinedSearch;
|
|
37
42
|
display_products?: DisplayProducts;
|
|
38
|
-
|
|
43
|
+
copilot_search_suggestion?: CopilotSearchSuggestion;
|
|
44
|
+
faceted_navigation_suggestion?: FacetedNavigationSuggestion;
|
|
45
|
+
suggestions?: (CopilotSearchSuggestion | FacetedNavigationSuggestion)[];
|
|
39
46
|
follow_up?: FollowUp;
|
|
40
47
|
partial_inquiry?: PartialInquiry;
|
|
41
48
|
inquiry?: Inquiry;
|
|
42
49
|
done?: Done;
|
|
43
50
|
error?: Error;
|
|
44
|
-
event?:
|
|
51
|
+
event?: CopilotEvent;
|
|
45
52
|
session_data?: SessionData;
|
|
46
53
|
session_info_reply?: SessionInformation;
|
|
47
|
-
session_events_reply?:
|
|
54
|
+
session_events_reply?: CopilotEvent[];
|
|
48
55
|
session_event_info?: string;
|
|
49
|
-
session_event_info_reply?:
|
|
56
|
+
session_event_info_reply?: ConnectAck | EventAck | FollowUp | Inquiry | DisplayProducts | RefinedSearch | Done | Error;
|
|
50
57
|
session_event_status?: string;
|
|
51
58
|
session_event_status_reply?: SessionEventStatusReply;
|
|
52
59
|
cancel?: Cancel;
|
|
60
|
+
return_fields?: ReturnedFields;
|
|
53
61
|
}
|
|
54
62
|
export { Root };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { CopilotEvent } from './CopilotEvent';
|
|
2
|
+
import type { RefinedSearch } from './RefinedSearch';
|
|
3
|
+
interface SessionData<T extends object = RefinedSearch> {
|
|
4
|
+
events?: Record<string, CopilotEvent<T>>;
|
|
5
|
+
event_source_map?: Record<string, string[]>;
|
|
5
6
|
}
|
|
6
7
|
export { SessionData };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SessionData } from './SessionData';
|
|
2
|
-
|
|
2
|
+
import type { RefinedSearch } from './RefinedSearch';
|
|
3
|
+
interface SessionInformation<T extends object = RefinedSearch> {
|
|
3
4
|
session_id?: string;
|
|
4
5
|
created_at?: string;
|
|
5
6
|
last_active_at?: string;
|
|
6
7
|
status?: string;
|
|
7
|
-
data?: SessionData
|
|
8
|
-
metadata?: Map<string, any>;
|
|
8
|
+
data?: SessionData<T>;
|
|
9
9
|
}
|
|
10
10
|
export { SessionInformation };
|
|
@@ -2,32 +2,38 @@ export * from './Root';
|
|
|
2
2
|
export * from './CommonRequiredFields';
|
|
3
3
|
export * from './CommonFields';
|
|
4
4
|
export * from './CommonEventFields';
|
|
5
|
+
export * from './CommonMetadata';
|
|
6
|
+
export * from './WorkflowMetadata';
|
|
5
7
|
export * from './ConnectAckMetadata';
|
|
6
8
|
export * from './ConnectAck';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
+
export * from './ConnectAckMessageFields';
|
|
10
|
+
export * from './SearchParams';
|
|
9
11
|
export * from './FacetValue';
|
|
10
12
|
export * from './Facet';
|
|
11
13
|
export * from './CopilotSearch';
|
|
12
14
|
export * from './FacetedNavigation';
|
|
15
|
+
export * from './EventAckNames';
|
|
13
16
|
export * from './EventAck';
|
|
14
|
-
export * from './
|
|
17
|
+
export * from './Cancel';
|
|
18
|
+
export * from './EventAckMessageFields';
|
|
15
19
|
export * from './RefinedSearch';
|
|
16
20
|
export * from './RefinedSearchMessageFields';
|
|
17
21
|
export * from './DisplayProducts';
|
|
18
22
|
export * from './DisplayProductsMessageFields';
|
|
19
|
-
export * from './
|
|
23
|
+
export * from './CopilotSearchSuggestion';
|
|
24
|
+
export * from './FacetedNavigationSuggestion';
|
|
20
25
|
export * from './FollowUp';
|
|
21
|
-
export * from './
|
|
26
|
+
export * from './FollowUpMessageFields';
|
|
22
27
|
export * from './PartialInquiry';
|
|
23
28
|
export * from './PartialInquiryMessageFields';
|
|
24
29
|
export * from './Inquiry';
|
|
30
|
+
export * from './InquiryMessageFields';
|
|
25
31
|
export * from './Done';
|
|
32
|
+
export * from './DoneMessageFields';
|
|
26
33
|
export * from './Error';
|
|
27
34
|
export * from './ErrorMessageFields';
|
|
28
|
-
export * from './
|
|
35
|
+
export * from './CopilotEvent';
|
|
29
36
|
export * from './SessionData';
|
|
30
37
|
export * from './SessionInformation';
|
|
31
|
-
export * from './SessionEventInformationReply';
|
|
32
38
|
export * from './SessionEventStatusReply';
|
|
33
|
-
export * from './
|
|
39
|
+
export * from './ReturnedFields';
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cimulate/copilot-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A lightweight API client SDK for Cimulate Copilot",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.cjs.js",
|
|
6
7
|
"module": "dist/index.esm.js",
|
|
7
8
|
"browser": "dist/index.umd.js",
|
|
@@ -14,8 +15,9 @@
|
|
|
14
15
|
"author": "support@cimulate.ai",
|
|
15
16
|
"license": "MIT",
|
|
16
17
|
"dependencies": {
|
|
18
|
+
"deepmerge": "^4.3.1",
|
|
17
19
|
"socket.io-client": "^4.7.5",
|
|
18
|
-
"ts-
|
|
20
|
+
"ts-case-convert": "^2.1.0"
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"react": "^18.2.0",
|
|
@@ -29,16 +31,16 @@
|
|
|
29
31
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
30
32
|
"@rollup/plugin-json": "^6.1.0",
|
|
31
33
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
34
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
32
35
|
"@rollup/plugin-typescript": "^9.0.0",
|
|
33
|
-
"@types/js-yaml": "^4.0.9",
|
|
34
36
|
"@types/eslint": "^9.6.1",
|
|
35
37
|
"@types/estree": "^1.0.6",
|
|
38
|
+
"@types/js-yaml": "^4.0.9",
|
|
36
39
|
"babel-loader": "^9.2.1",
|
|
37
40
|
"js-yaml": "^4.1.0",
|
|
38
41
|
"rollup": "^2.42.0",
|
|
39
42
|
"rollup-plugin-hash": "^1.3.0",
|
|
40
43
|
"rollup-plugin-output": "^1.0.1",
|
|
41
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
42
44
|
"source-map-explorer": "^2.5.3",
|
|
43
45
|
"tsx": "^4.19.2",
|
|
44
46
|
"typescript": "^5.7.3",
|
package/rollup.config.js
CHANGED
|
@@ -3,7 +3,7 @@ import resolve from '@rollup/plugin-node-resolve';
|
|
|
3
3
|
import commonjs from '@rollup/plugin-commonjs';
|
|
4
4
|
import json from '@rollup/plugin-json';
|
|
5
5
|
import outputHash from 'rollup-plugin-output';
|
|
6
|
-
import
|
|
6
|
+
import terser from '@rollup/plugin-terser';
|
|
7
7
|
import typescript from "@rollup/plugin-typescript";
|
|
8
8
|
// import polyfillNode from 'rollup-plugin-polyfill-node';
|
|
9
9
|
|
package/src/copilot.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import io, { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
|
|
2
|
-
import { merge } from "ts-deepmerge";
|
|
3
2
|
|
|
4
|
-
import type
|
|
3
|
+
import type {
|
|
4
|
+
ConnectAck,
|
|
5
|
+
DisplayProducts,
|
|
6
|
+
Done,
|
|
7
|
+
Error,
|
|
8
|
+
EventAck,
|
|
9
|
+
EventAckNames,
|
|
10
|
+
FollowUp,
|
|
11
|
+
Inquiry,
|
|
12
|
+
PartialInquiry,
|
|
13
|
+
RefinedSearch,
|
|
14
|
+
ReturnedFields,
|
|
15
|
+
SessionInformation,
|
|
16
|
+
} from "./model";
|
|
17
|
+
import deepmerge from "deepmerge";
|
|
5
18
|
|
|
6
19
|
type SocketIOOptions = Partial<ManagerOptions & SocketOptions>;
|
|
7
20
|
|
|
@@ -27,7 +40,9 @@ const socketDefaults: SocketIOOptions = {
|
|
|
27
40
|
timeout: 10000,
|
|
28
41
|
};
|
|
29
42
|
|
|
30
|
-
class CimulateCopilot
|
|
43
|
+
export default class CimulateCopilot<
|
|
44
|
+
T extends ReturnedFields = ReturnedFields
|
|
45
|
+
> {
|
|
31
46
|
private socket: Socket;
|
|
32
47
|
|
|
33
48
|
constructor({
|
|
@@ -38,9 +53,10 @@ class CimulateCopilot {
|
|
|
38
53
|
}: CimulateCopilotOptions) {
|
|
39
54
|
const socketioEndpoint = `${baseUrl}${namespace}`;
|
|
40
55
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
const options: SocketIOOptions[] = [
|
|
57
|
+
socketDefaults,
|
|
58
|
+
socketOptions,
|
|
59
|
+
{
|
|
44
60
|
withCredentials: true, // enables cookies
|
|
45
61
|
transportOptions: {
|
|
46
62
|
polling: {
|
|
@@ -49,8 +65,10 @@ class CimulateCopilot {
|
|
|
49
65
|
},
|
|
50
66
|
},
|
|
51
67
|
},
|
|
52
|
-
}
|
|
53
|
-
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
this.socket = io(socketioEndpoint, deepmerge.all(options));
|
|
54
72
|
}
|
|
55
73
|
|
|
56
74
|
connect() {
|
|
@@ -58,8 +76,11 @@ class CimulateCopilot {
|
|
|
58
76
|
}
|
|
59
77
|
|
|
60
78
|
search(
|
|
61
|
-
{
|
|
62
|
-
|
|
79
|
+
{
|
|
80
|
+
userPrompt,
|
|
81
|
+
searchParams,
|
|
82
|
+
}: { userPrompt?: string; searchParams: SearchParams },
|
|
83
|
+
callback?: (searchAck: EventAck<EventAckNames.COPILOT_SEARCH_ACK>) => void
|
|
63
84
|
) {
|
|
64
85
|
const payload = {
|
|
65
86
|
user_prompt: userPrompt,
|
|
@@ -74,7 +95,9 @@ class CimulateCopilot {
|
|
|
74
95
|
|
|
75
96
|
facetedNavigation(
|
|
76
97
|
{ searchParams }: { searchParams: SearchParams },
|
|
77
|
-
callback?: (
|
|
98
|
+
callback?: (
|
|
99
|
+
facetedNavigationAck: EventAck<EventAckNames.FACETED_NAVIGATION_ACK>
|
|
100
|
+
) => void
|
|
78
101
|
) {
|
|
79
102
|
const payload = {
|
|
80
103
|
search_params: searchParams,
|
|
@@ -88,7 +111,7 @@ class CimulateCopilot {
|
|
|
88
111
|
|
|
89
112
|
cancelRequest(
|
|
90
113
|
{ eventId, reason }: { eventId: string; reason: string },
|
|
91
|
-
callback?: (cancelAck:
|
|
114
|
+
callback?: (cancelAck: EventAck<EventAckNames.CANCEL_ACK>) => void
|
|
92
115
|
) {
|
|
93
116
|
const payload = {
|
|
94
117
|
event_id: eventId,
|
|
@@ -101,43 +124,47 @@ class CimulateCopilot {
|
|
|
101
124
|
this.socket.emit("cancel", payload);
|
|
102
125
|
}
|
|
103
126
|
|
|
104
|
-
requestSessionInformation(
|
|
127
|
+
requestSessionInformation(
|
|
128
|
+
callback: (sessionInformation: SessionInformation<T>) => void
|
|
129
|
+
) {
|
|
105
130
|
this.socket.emit("session_info", callback);
|
|
106
131
|
}
|
|
107
132
|
|
|
108
|
-
onConnectAck(callback: (connectAck:
|
|
133
|
+
onConnectAck(callback: (connectAck: ConnectAck) => void) {
|
|
109
134
|
this.socket.on("connect_ack", callback);
|
|
110
135
|
}
|
|
111
136
|
|
|
112
|
-
onSearchAck(
|
|
137
|
+
onSearchAck(
|
|
138
|
+
callback: (searchAck: EventAck<EventAckNames.COPILOT_SEARCH_ACK>) => void
|
|
139
|
+
) {
|
|
113
140
|
this.socket.on("search_ack", callback);
|
|
114
141
|
}
|
|
115
142
|
|
|
116
|
-
onRefinedSearch(callback: (refinedSearch:
|
|
143
|
+
onRefinedSearch(callback: (refinedSearch: RefinedSearch<T>) => void) {
|
|
117
144
|
this.socket.on("refined_search", callback);
|
|
118
145
|
}
|
|
119
146
|
|
|
120
|
-
onFollowUp(callback: (followUp:
|
|
147
|
+
onFollowUp(callback: (followUp: FollowUp) => void) {
|
|
121
148
|
this.socket.on("follow_up", callback);
|
|
122
149
|
}
|
|
123
150
|
|
|
124
|
-
onInquiry(callback: (inquiry:
|
|
151
|
+
onInquiry(callback: (inquiry: Inquiry) => void) {
|
|
125
152
|
this.socket.on("inquiry", callback);
|
|
126
153
|
}
|
|
127
154
|
|
|
128
|
-
onPartialInquiry(callback: (partialInquiry:
|
|
155
|
+
onPartialInquiry(callback: (partialInquiry: PartialInquiry) => void) {
|
|
129
156
|
this.socket.on("partial_inquiry", callback);
|
|
130
157
|
}
|
|
131
158
|
|
|
132
|
-
onDisplayProducts(callback: (displayProducts:
|
|
159
|
+
onDisplayProducts(callback: (displayProducts: DisplayProducts<T>) => void) {
|
|
133
160
|
this.socket.on("display_products", callback);
|
|
134
161
|
}
|
|
135
162
|
|
|
136
|
-
onDone(callback: (done:
|
|
163
|
+
onDone(callback: (done: Done) => void) {
|
|
137
164
|
this.socket.on("done", callback);
|
|
138
165
|
}
|
|
139
166
|
|
|
140
|
-
onError(callback: (error:
|
|
167
|
+
onError(callback: (error: Error) => void) {
|
|
141
168
|
this.socket.on("error", callback);
|
|
142
169
|
}
|
|
143
170
|
|
|
@@ -148,7 +175,4 @@ class CimulateCopilot {
|
|
|
148
175
|
onDisconnect(callback: (reason: string) => void) {
|
|
149
176
|
this.socket.on("disconnect", callback);
|
|
150
177
|
}
|
|
151
|
-
|
|
152
178
|
}
|
|
153
|
-
|
|
154
|
-
export default CimulateCopilot;
|
package/src/model/ConnectAck.ts
CHANGED
|
@@ -2,10 +2,10 @@ import {ConnectAckMetadata} from './ConnectAckMetadata';
|
|
|
2
2
|
interface ConnectAck {
|
|
3
3
|
session_id: string;
|
|
4
4
|
event_id: string;
|
|
5
|
-
event_name: string;
|
|
6
5
|
timestamp: string;
|
|
7
6
|
status: number;
|
|
8
7
|
message: string;
|
|
9
8
|
metadata: ConnectAckMetadata;
|
|
9
|
+
event_name: 'connect_ack';
|
|
10
10
|
}
|
|
11
11
|
export { ConnectAck };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {ConnectAckMetadata} from './ConnectAckMetadata';
|
|
2
|
-
interface
|
|
2
|
+
interface ConnectAckMessageFields {
|
|
3
3
|
status: number;
|
|
4
4
|
message: string;
|
|
5
5
|
metadata: ConnectAckMetadata;
|
|
6
|
+
event_name: 'connect_ack';
|
|
6
7
|
}
|
|
7
|
-
export {
|
|
8
|
+
export { ConnectAckMessageFields };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {ConnectAck} from './ConnectAck';
|
|
2
|
+
import {EventAck} from './EventAck';
|
|
3
|
+
import {FollowUp} from './FollowUp';
|
|
4
|
+
import {Inquiry} from './Inquiry';
|
|
5
|
+
import {DisplayProducts} from './DisplayProducts';
|
|
6
|
+
import {RefinedSearch} from './RefinedSearch';
|
|
7
|
+
import {Done} from './Done';
|
|
8
|
+
import {Error} from './Error';
|
|
9
|
+
import {CommonMetadata} from './CommonMetadata';
|
|
10
|
+
import type { ReturnedFields } from './ReturnedFields';
|
|
11
|
+
interface CopilotEvent<T extends object = ReturnedFields> {
|
|
12
|
+
id: string;
|
|
13
|
+
session_id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
event_source_id: string;
|
|
16
|
+
data: ConnectAck | EventAck | FollowUp | Inquiry | DisplayProducts<T> | RefinedSearch<T> | Done | Error;
|
|
17
|
+
created_at: string;
|
|
18
|
+
metadata: CommonMetadata;
|
|
19
|
+
}
|
|
20
|
+
export { CopilotEvent };
|