@constructor-io/constructorio-ui-asa 1.4.0 → 1.6.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 (39) hide show
  1. package/README.md +1 -1
  2. package/dist/constructorio-ui-asa-bundled.js +1 -1
  3. package/lib/cjs/components/Chat/Chat.js +5 -4
  4. package/lib/cjs/components/Chat/ChatInput.css +11 -0
  5. package/lib/cjs/components/Chat/ChatInput.js +8 -3
  6. package/lib/cjs/components/Chat/ChatMessageList.js +7 -3
  7. package/lib/cjs/components/Chat/FollowUpRefinement.css +62 -0
  8. package/lib/cjs/components/Chat/FollowUpRefinement.js +30 -0
  9. package/lib/cjs/components/icons/StopIcon.js +9 -0
  10. package/lib/cjs/components/icons/index.js +3 -1
  11. package/lib/cjs/hooks/asaStreamHandlers.js +11 -1
  12. package/lib/cjs/hooks/useAsaResults.js +62 -13
  13. package/lib/cjs/styles.css +1 -0
  14. package/lib/cjs/utils/translate.js +2 -0
  15. package/lib/cjs/version.js +1 -1
  16. package/lib/mjs/components/Chat/Chat.js +5 -4
  17. package/lib/mjs/components/Chat/ChatInput.css +11 -0
  18. package/lib/mjs/components/Chat/ChatInput.js +9 -4
  19. package/lib/mjs/components/Chat/ChatMessageList.js +7 -3
  20. package/lib/mjs/components/Chat/FollowUpRefinement.css +62 -0
  21. package/lib/mjs/components/Chat/FollowUpRefinement.js +26 -0
  22. package/lib/mjs/components/icons/StopIcon.js +5 -0
  23. package/lib/mjs/components/icons/index.js +1 -0
  24. package/lib/mjs/hooks/asaStreamHandlers.js +13 -0
  25. package/lib/mjs/hooks/useAsaResults.js +62 -14
  26. package/lib/mjs/styles.css +1 -0
  27. package/lib/mjs/utils/translate.js +2 -0
  28. package/lib/mjs/version.js +1 -1
  29. package/lib/types/components/Chat/Chat.d.ts +13 -0
  30. package/lib/types/components/Chat/ChatInput.d.ts +11 -1
  31. package/lib/types/components/Chat/ChatMessageList.d.ts +6 -2
  32. package/lib/types/components/Chat/FollowUpRefinement.d.ts +14 -0
  33. package/lib/types/components/icons/StopIcon.d.ts +2 -0
  34. package/lib/types/components/icons/index.d.ts +1 -0
  35. package/lib/types/hooks/asaStreamHandlers.d.ts +1 -0
  36. package/lib/types/index.d.ts +1 -1
  37. package/lib/types/types.d.ts +35 -3
  38. package/lib/types/version.d.ts +1 -1
  39. package/package.json +3 -3
@@ -1,5 +1,6 @@
1
1
  export { default as ChatBubbleDarkIcon } from './ChatBubbleDarkIcon';
2
2
  export { default as ChatBubbleLightIcon } from './ChatBubbleLightIcon';
3
3
  export { default as SendArrowIcon } from './SendArrowIcon';
4
+ export { default as StopIcon } from './StopIcon';
4
5
  export { default as SendPlaneIcon } from './SendPlaneIcon';
5
6
  export { default as ArrowRightIcon } from './ArrowRightIcon';
@@ -3,6 +3,7 @@ import { ResultGroupMeta, ChatMessage } from '../types';
3
3
  export type MessageUpdater = Dispatch<SetStateAction<ChatMessage[]>>;
4
4
  export declare function handleSearchResult(data: any, pendingGroup: ResultGroupMeta | null, assistantId: string, setMessages: MessageUpdater): ResultGroupMeta | null;
5
5
  export declare function handleMessage(data: any, assistantId: string, setMessages: MessageUpdater): void;
6
+ export declare function handleFollowUpRefinement(data: any, assistantId: string, setMessages: MessageUpdater): void;
6
7
  export declare function handleServerError(assistantId: string, setMessages: MessageUpdater): void;
7
8
  export declare function handleStreamEnd(assistantId: string, setMessages: MessageUpdater): void;
8
9
  export declare function handleStreamError(assistantId: string, setMessages: MessageUpdater): void;
@@ -12,4 +12,4 @@ export type { UseAsaTrackingProps, UseAsaTrackingReturn } from './hooks/useAsaTr
12
12
  export { normalizeItemToProduct } from './utils/productNormalizer';
13
13
  export type { Product, NormalizeOptions } from './utils/productNormalizer';
14
14
  export { ConstructorIOClient } from './types';
15
- export type { Nullable, CioAsaProviderProps, AsaContextValue, CioClientOptions, RequestConfigs, Formatters, UrlHelpers, QueryParamEncodingOptions, DefaultQueryStringMap, Translations, ChatMessage, ChatMessageStatus, ResultGroup, ResultGroupMeta, SearchResultEventRequest, UseAsaResultsOptions, UseChatReturn, AsaCallbacks, AssistantSubmitSource, AssistantTrackedItem, ChatComponentOverrides, WelcomeScreenOverrides, ChatInputOverrides, AiMessageOverrides, ResultsBlockOverrides, ComponentOverrideProps, IncludeComponentOverrides, ChatHeaderRenderProps, ChatInputRenderProps, WelcomeScreenTitleRenderProps, WelcomeScreenInputRenderProps, SuggestedQuestionsRenderProps, UserMessageRenderProps, AiMessageLoaderRenderProps, AiMessageTextRenderProps, ResultsGroupTitleRenderProps, ResultsViewMoreRenderProps, } from './types';
15
+ export type { Nullable, CioAsaProviderProps, AsaContextValue, CioClientOptions, RequestConfigs, Formatters, UrlHelpers, QueryParamEncodingOptions, DefaultQueryStringMap, Translations, ChatMessage, ChatMessageStatus, FollowUpRefinement, ResultGroup, ResultGroupMeta, SearchResultEventRequest, UseAsaResultsOptions, UseChatReturn, AsaCallbacks, AssistantSubmitSource, AssistantTrackedItem, ChatComponentOverrides, WelcomeScreenOverrides, ChatInputOverrides, AiMessageOverrides, ResultsBlockOverrides, ComponentOverrideProps, IncludeComponentOverrides, ChatHeaderRenderProps, ChatInputRenderProps, WelcomeScreenTitleRenderProps, WelcomeScreenInputRenderProps, SuggestedQuestionsRenderProps, UserMessageRenderProps, AiMessageLoaderRenderProps, AiMessageTextRenderProps, FollowUpRefinementRenderProps, ResultsGroupTitleRenderProps, ResultsViewMoreRenderProps, } from './types';
@@ -70,6 +70,13 @@ export interface ChatMessage {
70
70
  intent?: string;
71
71
  intentResultId?: string;
72
72
  threadId?: string;
73
+ /** Narrowing question the agent asked at the end of this turn, from a `follow_up_refinement` event. */
74
+ refinement?: FollowUpRefinement;
75
+ }
76
+ /** A narrowing question with selectable options, emitted by the agent as a `follow_up_refinement` event. */
77
+ export interface FollowUpRefinement {
78
+ question: string;
79
+ options: string[];
73
80
  }
74
81
  export type ChatMessageStatus = 'idle' | 'loading' | 'streaming' | 'done' | 'error';
75
82
  /**
@@ -127,14 +134,20 @@ export interface UseChatReturn {
127
134
  messages: ChatMessage[];
128
135
  sendMessage: (text: string, source?: AssistantSubmitSource) => void;
129
136
  isStreaming: boolean;
137
+ /**
138
+ * Cancel the in-flight request, keeping the conversation. The partial reply is settled
139
+ * as `done` and the thread id is kept, so the next message continues the same
140
+ * conversation. No-op when nothing is streaming. Use `clearHistory` to reset instead.
141
+ */
142
+ abort: () => void;
130
143
  clearHistory: () => void;
131
144
  }
132
145
  export interface UseAsaResultsOptions {
133
146
  /** Seed the thread id (e.g. loaded from browser storage) to resume a prior conversation. Read once on mount. */
134
147
  initialThreadId?: string;
135
148
  }
136
- /** How an intent was submitted: typed into the input, or a suggestion chip clicked. */
137
- export type AssistantSubmitSource = 'input' | 'suggestion';
149
+ /** How an intent was submitted: typed input, a welcome-screen suggestion chip, or a refinement chip. */
150
+ export type AssistantSubmitSource = 'input' | 'suggestion' | 'refinement';
138
151
  /** An item within a viewed/clicked search_result pod. */
139
152
  export interface AssistantTrackedItem {
140
153
  itemId?: string;
@@ -147,7 +160,7 @@ export interface AssistantTrackedItem {
147
160
  * so consumers can mirror ASA analytics into their own systems. All are optional.
148
161
  */
149
162
  export interface AsaCallbacks {
150
- /** User submitted an intent (typed) or clicked a suggestion. */
163
+ /** User submitted an intent (typed) or clicked a suggestion / refinement chip. */
151
164
  onAssistantSubmit?: (payload: {
152
165
  intent: string;
153
166
  source: AssistantSubmitSource;
@@ -198,6 +211,7 @@ export type Translations = {
198
211
  'CioAsa.input.placeholder'?: string;
199
212
  'CioAsa.input.ariaLabel'?: string;
200
213
  'CioAsa.input.sendAriaLabel'?: string;
214
+ 'CioAsa.input.stopAriaLabel'?: string;
201
215
  'CioAsa.welcome.title'?: string;
202
216
  'CioAsa.welcome.placeholder'?: string;
203
217
  'CioAsa.welcome.sendButton'?: string;
@@ -212,6 +226,7 @@ export type Translations = {
212
226
  'CioAsa.results.viewMore'?: string;
213
227
  'CioAsa.results.addToCart'?: string;
214
228
  'CioAsa.results.saleBadge'?: string;
229
+ 'CioAsa.refinement.ariaLabel'?: string;
215
230
  'CioAsa.error.message'?: string;
216
231
  };
217
232
  export interface ChatHeaderRenderProps {
@@ -224,6 +239,14 @@ export interface ChatInputRenderProps {
224
239
  onSubmit: () => void;
225
240
  placeholder: string;
226
241
  isDisabled: boolean;
242
+ /**
243
+ * Whether a reply is currently streaming. Pair it with `onAbort` to offer a cancel
244
+ * control while it is true — the built-in stop button is off by default, so an override
245
+ * is often the only way a user can cancel.
246
+ */
247
+ isStreaming: boolean;
248
+ /** Cancel the in-flight reply. Keeps the conversation and the thread. */
249
+ onAbort: () => void;
227
250
  }
228
251
  export interface WelcomeScreenTitleRenderProps {
229
252
  text: string;
@@ -248,6 +271,14 @@ export interface AiMessageLoaderRenderProps {
248
271
  export interface AiMessageTextRenderProps {
249
272
  text: string;
250
273
  }
274
+ export interface FollowUpRefinementRenderProps {
275
+ question: string;
276
+ options: string[];
277
+ /** Sends the option as a follow-up message. No-op while `isDisabled`. */
278
+ onOptionClick: (option: string) => void;
279
+ /** True for earlier refinements and while a response is streaming. */
280
+ isDisabled: boolean;
281
+ }
251
282
  export interface ResultsGroupTitleRenderProps {
252
283
  label: string;
253
284
  }
@@ -266,6 +297,7 @@ export interface ChatInputOverrides {
266
297
  export interface AiMessageOverrides {
267
298
  loader?: ComponentOverrideProps<AiMessageLoaderRenderProps>;
268
299
  text?: ComponentOverrideProps<AiMessageTextRenderProps>;
300
+ followUpRefinement?: ComponentOverrideProps<FollowUpRefinementRenderProps>;
269
301
  }
270
302
  export interface ResultsBlockOverrides {
271
303
  groupTitle?: ComponentOverrideProps<ResultsGroupTitleRenderProps>;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.4.0";
1
+ declare const _default: "1.6.0";
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.4.0",
3
+ "version": "1.6.0",
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.91.0",
72
+ "@constructor-io/constructorio-client-javascript": "^2.93.1",
73
73
  "@constructor-io/constructorio-ui-components": "^1.6.0",
74
74
  "react": ">=16.12.0",
75
75
  "react-dom": ">=16.12.0",
@@ -79,7 +79,7 @@
79
79
  "@babel/preset-env": "^7.28.3",
80
80
  "@babel/preset-react": "^7.27.1",
81
81
  "@babel/preset-typescript": "^7.27.1",
82
- "@constructor-io/constructorio-client-javascript": "^2.91.0",
82
+ "@constructor-io/constructorio-client-javascript": "2.93.1",
83
83
  "@constructor-io/constructorio-ui-components": "^1.6.0",
84
84
  "@cspell/eslint-plugin": "^6.18.1",
85
85
  "@storybook/addon-a11y": "^8.6.14",