@constructor-io/constructorio-ui-asa 1.0.0 → 1.1.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/lib/cjs/components/Chat/Chat.js +10 -1
- package/lib/cjs/components/Chat/ChatMessageList.js +1 -1
- package/lib/cjs/components/Chat/WelcomeScreen.js +3 -2
- package/lib/cjs/components/CioAsaProvider/CioAsaProvider.js +4 -2
- package/lib/cjs/components/ResultsBlock/ResultsBlock.js +13 -38
- package/lib/cjs/components/ResultsBlock/ResultsGroup.js +109 -0
- package/lib/cjs/hooks/asaStreamHandlers.js +3 -1
- package/lib/cjs/hooks/useAsaResults.js +78 -14
- package/lib/cjs/hooks/useAsaTracking.js +66 -0
- package/lib/cjs/hooks/useViewportTracking.js +39 -0
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/utils/productNormalizer.js +2 -11
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/Chat/Chat.js +10 -1
- package/lib/mjs/components/Chat/ChatMessageList.js +1 -1
- package/lib/mjs/components/Chat/WelcomeScreen.js +3 -2
- package/lib/mjs/components/CioAsaProvider/CioAsaProvider.js +4 -2
- package/lib/mjs/components/ResultsBlock/ResultsBlock.js +12 -45
- package/lib/mjs/components/ResultsBlock/ResultsGroup.js +117 -0
- package/lib/mjs/hooks/asaStreamHandlers.js +8 -1
- package/lib/mjs/hooks/useAsaResults.js +72 -10
- package/lib/mjs/hooks/useAsaTracking.js +91 -0
- package/lib/mjs/hooks/useViewportTracking.js +36 -0
- package/lib/mjs/index.js +1 -0
- package/lib/mjs/utils/productNormalizer.js +1 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/Chat/WelcomeScreen.d.ts +2 -2
- package/lib/types/components/ResultsBlock/ResultsBlock.d.ts +4 -1
- package/lib/types/components/ResultsBlock/ResultsGroup.d.ts +36 -0
- package/lib/types/hooks/useAsaTracking.d.ts +54 -0
- package/lib/types/hooks/useViewportTracking.d.ts +15 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/types/types.d.ts +63 -1
- package/lib/types/utils/productNormalizer.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Tracker } from '@constructor-io/constructorio-client-javascript/lib/types/constructorio';
|
|
2
|
+
import { AssistantTrackedItem } from '../types';
|
|
3
|
+
export interface UseAsaTrackingProps {
|
|
4
|
+
tracker?: Tracker;
|
|
5
|
+
section?: string;
|
|
6
|
+
/** Thread id of the current conversation, forwarded to every event when present. */
|
|
7
|
+
threadId?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TrackResultLoadStartedArgs {
|
|
10
|
+
intent: string;
|
|
11
|
+
intentResultId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TrackResultLoadFinishedArgs {
|
|
14
|
+
intent: string;
|
|
15
|
+
searchResultCount: number;
|
|
16
|
+
intentResultId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TrackResultClickArgs {
|
|
19
|
+
intent: string;
|
|
20
|
+
searchResultId: string;
|
|
21
|
+
intentResultId?: string;
|
|
22
|
+
itemId?: string;
|
|
23
|
+
itemName?: string;
|
|
24
|
+
variationId?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TrackResultViewArgs {
|
|
27
|
+
intent: string;
|
|
28
|
+
searchResultId: string;
|
|
29
|
+
numResultsViewed: number;
|
|
30
|
+
intentResultId?: string;
|
|
31
|
+
items?: AssistantTrackedItem[];
|
|
32
|
+
}
|
|
33
|
+
export interface TrackSearchSubmitArgs {
|
|
34
|
+
intent: string;
|
|
35
|
+
searchTerm: string;
|
|
36
|
+
userInput: string;
|
|
37
|
+
searchResultId: string;
|
|
38
|
+
intentResultId?: string;
|
|
39
|
+
groupId?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface UseAsaTrackingReturn {
|
|
42
|
+
trackSubmit: (intent: string) => void;
|
|
43
|
+
trackResultLoadStarted: (args: TrackResultLoadStartedArgs) => void;
|
|
44
|
+
trackResultLoadFinished: (args: TrackResultLoadFinishedArgs) => void;
|
|
45
|
+
trackResultClick: (args: TrackResultClickArgs) => void;
|
|
46
|
+
trackResultView: (args: TrackResultViewArgs) => void;
|
|
47
|
+
trackSearchSubmit: (args: TrackSearchSubmitArgs) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Fires ASA behavioral tracking events through the Constructor client. Each returned
|
|
51
|
+
* function maps to one `trackAssistant*` beacon and merges in `section` + `threadId`.
|
|
52
|
+
* Mirrors the tracking-hook pattern used by constructorio-ui-pia.
|
|
53
|
+
*/
|
|
54
|
+
export default function useAsaTracking({ tracker, section, threadId, }: UseAsaTrackingProps): UseAsaTrackingReturn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface UseViewportTrackingProps {
|
|
2
|
+
/** Fired once, the first time the observed element becomes at least 50% visible. */
|
|
3
|
+
onView: () => void;
|
|
4
|
+
/** When false, no observer is attached (e.g. tracking context unavailable). */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface UseViewportTrackingReturn {
|
|
8
|
+
ref: (node: HTMLElement | null) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Fires `onView` once when the observed element scrolls into the viewport, modeling a
|
|
12
|
+
* per-pod `assistant_search_result_view` impression. Unlike the PIA widget-level view
|
|
13
|
+
* tracker, this fires a single impression per pod (not repeated enter/exit cycles).
|
|
14
|
+
*/
|
|
15
|
+
export default function useViewportTracking({ onView, enabled, }: UseViewportTrackingProps): UseViewportTrackingReturn;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export type { AspectRatio } from './components/ResultsBlock/ResultsBlock';
|
|
|
6
6
|
export { default as Button } from './components/Button/Button';
|
|
7
7
|
export type { ButtonProps } from './components/Button/Button';
|
|
8
8
|
export { default as useAsaResults } from './hooks/useAsaResults';
|
|
9
|
+
export { default as useAsaTracking } from './hooks/useAsaTracking';
|
|
10
|
+
export type { UseAsaTrackingProps, UseAsaTrackingReturn } from './hooks/useAsaTracking';
|
|
9
11
|
export { normalizeItemToProduct } from './utils/productNormalizer';
|
|
10
12
|
export type { Product, NormalizeOptions } from './utils/productNormalizer';
|
|
11
13
|
export { ConstructorIOClient } from './types';
|
|
12
|
-
export type { Nullable, CioAsaProviderProps, AsaContextValue, CioClientOptions, RequestConfigs, Formatters, UrlHelpers, QueryParamEncodingOptions, DefaultQueryStringMap, Translations, ChatMessage, ChatMessageStatus, ResultGroup, ResultGroupMeta, UseChatReturn, ChatComponentOverrides, WelcomeScreenOverrides, ChatInputOverrides, AiMessageOverrides, ResultsBlockOverrides, ComponentOverrideProps, IncludeComponentOverrides, ChatHeaderRenderProps, ChatInputRenderProps, WelcomeScreenTitleRenderProps, WelcomeScreenInputRenderProps, SuggestedQuestionsRenderProps, UserMessageRenderProps, AiMessageLoaderRenderProps, AiMessageTextRenderProps, ResultsGroupTitleRenderProps, ResultsViewMoreRenderProps, } from './types';
|
|
14
|
+
export type { Nullable, CioAsaProviderProps, AsaContextValue, CioClientOptions, RequestConfigs, Formatters, UrlHelpers, QueryParamEncodingOptions, DefaultQueryStringMap, Translations, ChatMessage, ChatMessageStatus, ResultGroup, ResultGroupMeta, UseChatReturn, AsaCallbacks, AssistantSubmitSource, AssistantTrackedItem, ChatComponentOverrides, WelcomeScreenOverrides, ChatInputOverrides, AiMessageOverrides, ResultsBlockOverrides, ComponentOverrideProps, IncludeComponentOverrides, ChatHeaderRenderProps, ChatInputRenderProps, WelcomeScreenTitleRenderProps, WelcomeScreenInputRenderProps, SuggestedQuestionsRenderProps, UserMessageRenderProps, AiMessageLoaderRenderProps, AiMessageTextRenderProps, ResultsGroupTitleRenderProps, ResultsViewMoreRenderProps, } from './types';
|
package/lib/types/types.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface AsaContextValue {
|
|
|
19
19
|
staticRequestConfigs: RequestConfigs;
|
|
20
20
|
formatters: Formatters;
|
|
21
21
|
urlHelpers: UrlHelpers;
|
|
22
|
+
callbacks?: AsaCallbacks;
|
|
23
|
+
section?: string;
|
|
22
24
|
}
|
|
23
25
|
export interface RequestConfigs extends IAgentParameters {
|
|
24
26
|
intent?: string;
|
|
@@ -65,6 +67,9 @@ export interface ChatMessage {
|
|
|
65
67
|
text: string;
|
|
66
68
|
groups?: ResultGroup[];
|
|
67
69
|
status: ChatMessageStatus;
|
|
70
|
+
intent?: string;
|
|
71
|
+
intentResultId?: string;
|
|
72
|
+
threadId?: string;
|
|
68
73
|
}
|
|
69
74
|
export type ChatMessageStatus = 'idle' | 'loading' | 'streaming' | 'done' | 'error';
|
|
70
75
|
export interface ResultGroupMeta {
|
|
@@ -78,13 +83,70 @@ export interface ResultGroupMeta {
|
|
|
78
83
|
export interface ResultGroup {
|
|
79
84
|
group: ResultGroupMeta;
|
|
80
85
|
searchResults: Record<string, unknown>[];
|
|
86
|
+
searchResultId?: string;
|
|
87
|
+
intentResultId?: string;
|
|
81
88
|
}
|
|
82
89
|
export interface UseChatReturn {
|
|
83
90
|
messages: ChatMessage[];
|
|
84
|
-
sendMessage: (text: string) => void;
|
|
91
|
+
sendMessage: (text: string, source?: AssistantSubmitSource) => void;
|
|
85
92
|
isStreaming: boolean;
|
|
86
93
|
clearHistory: () => void;
|
|
87
94
|
}
|
|
95
|
+
/** How an intent was submitted: typed into the input, or a suggestion chip clicked. */
|
|
96
|
+
export type AssistantSubmitSource = 'input' | 'suggestion';
|
|
97
|
+
/** An item within a viewed/clicked search_result pod. */
|
|
98
|
+
export interface AssistantTrackedItem {
|
|
99
|
+
itemId?: string;
|
|
100
|
+
itemName?: string;
|
|
101
|
+
variationId?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Optional consumer callbacks fired alongside the built-in behavioral tracking.
|
|
105
|
+
* Each fires immediately after its corresponding `trackAssistant*` beacon is sent,
|
|
106
|
+
* so consumers can mirror ASA analytics into their own systems. All are optional.
|
|
107
|
+
*/
|
|
108
|
+
export interface AsaCallbacks {
|
|
109
|
+
/** User submitted an intent (typed) or clicked a suggestion. */
|
|
110
|
+
onAssistantSubmit?: (payload: {
|
|
111
|
+
intent: string;
|
|
112
|
+
source: AssistantSubmitSource;
|
|
113
|
+
}) => void;
|
|
114
|
+
/** The ASA response stream started. */
|
|
115
|
+
onResultLoadStart?: (payload: {
|
|
116
|
+
intent: string;
|
|
117
|
+
intentResultId?: string;
|
|
118
|
+
}) => void;
|
|
119
|
+
/** The ASA response stream finished; `searchResultCount` = number of pods loaded. */
|
|
120
|
+
onResultLoadFinish?: (payload: {
|
|
121
|
+
intent: string;
|
|
122
|
+
searchResultCount: number;
|
|
123
|
+
intentResultId?: string;
|
|
124
|
+
}) => void;
|
|
125
|
+
/** A product inside a search_result pod was clicked. */
|
|
126
|
+
onResultClick?: (payload: {
|
|
127
|
+
intent: string;
|
|
128
|
+
searchResultId: string;
|
|
129
|
+
intentResultId?: string;
|
|
130
|
+
item: AssistantTrackedItem;
|
|
131
|
+
}) => void;
|
|
132
|
+
/** A search_result pod scrolled into view. */
|
|
133
|
+
onResultView?: (payload: {
|
|
134
|
+
intent: string;
|
|
135
|
+
searchResultId: string;
|
|
136
|
+
intentResultId?: string;
|
|
137
|
+
numResultsViewed: number;
|
|
138
|
+
items?: AssistantTrackedItem[];
|
|
139
|
+
}) => void;
|
|
140
|
+
/** A search query inside a search_result pod was submitted (e.g. "View more"). */
|
|
141
|
+
onSearchSubmit?: (payload: {
|
|
142
|
+
intent: string;
|
|
143
|
+
searchTerm: string;
|
|
144
|
+
userInput: string;
|
|
145
|
+
searchResultId: string;
|
|
146
|
+
intentResultId?: string;
|
|
147
|
+
groupId?: string;
|
|
148
|
+
}) => void;
|
|
149
|
+
}
|
|
88
150
|
/**
|
|
89
151
|
* Translations type for internationalizing UI strings.
|
|
90
152
|
* All keys are optional — any non-provided translation will fall back to the English default.
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.1.1";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-ui-asa",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Constructor.io AI Shopping Agent UI library for web applications",
|
|
5
5
|
"author": "constructor.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"prepare": "husky install"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@constructor-io/constructorio-client-javascript": "^2.
|
|
72
|
+
"@constructor-io/constructorio-client-javascript": "^2.91.0",
|
|
73
73
|
"@constructor-io/constructorio-ui-components": "^1.6.0",
|
|
74
74
|
"react": ">=16.12.0",
|
|
75
75
|
"react-dom": ">=16.12.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@axe-core/react": "^4.7.0",
|
|
80
|
-
"@constructor-io/constructorio-client-javascript": "^2.
|
|
80
|
+
"@constructor-io/constructorio-client-javascript": "^2.91.0",
|
|
81
81
|
"@constructor-io/constructorio-ui-components": "^1.6.0",
|
|
82
82
|
"@babel/preset-env": "^7.28.3",
|
|
83
83
|
"@babel/preset-react": "^7.27.1",
|
|
@@ -132,8 +132,8 @@
|
|
|
132
132
|
},
|
|
133
133
|
"dependencies": {},
|
|
134
134
|
"overrides": {
|
|
135
|
-
"brace-expansion@1": "1.1.
|
|
136
|
-
"brace-expansion@2": "2.1.
|
|
135
|
+
"brace-expansion@1": "1.1.18",
|
|
136
|
+
"brace-expansion@2": "2.1.4",
|
|
137
137
|
"minimatch@9": "9.0.9",
|
|
138
138
|
"form-data": "4.0.6",
|
|
139
139
|
"joi": "17.13.4",
|