@constructor-io/constructorio-ui-pia 2.10.2 → 2.10.4
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/constructorio-ui-pia-bundled.js +56 -56
- package/lib/cjs/components/CioPia/CioPia.js +2 -1
- package/lib/cjs/components/Input/Input.js +2 -6
- package/lib/cjs/components/SuggestedQuestion/SuggestedQuestion.js +3 -7
- package/lib/cjs/components/icons/QuestionIcon.js +9 -0
- package/lib/cjs/components/icons/SendIcon.js +9 -0
- package/lib/cjs/components/icons/SparklesIcon.js +11 -0
- package/lib/cjs/components/icons/index.js +12 -0
- package/lib/cjs/errors.js +19 -0
- package/lib/cjs/hooks/mocks/agent.js +13 -8
- package/lib/cjs/hooks/useAnswerResults.js +6 -19
- package/lib/cjs/hooks/useCioPia.js +3 -1
- package/lib/cjs/hooks/useSuggestedQuestions.js +8 -4
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/styles.css +0 -1
- package/lib/cjs/utils/transformers.js +22 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioPia/CioPia.js +2 -1
- package/lib/mjs/components/Input/Input.js +1 -5
- package/lib/mjs/components/SuggestedQuestion/SuggestedQuestion.js +3 -7
- package/lib/mjs/components/icons/QuestionIcon.js +5 -0
- package/lib/mjs/components/icons/SendIcon.js +5 -0
- package/lib/mjs/components/icons/SparklesIcon.js +7 -0
- package/lib/mjs/components/icons/index.js +3 -0
- package/lib/mjs/errors.js +16 -0
- package/lib/mjs/hooks/mocks/agent.js +13 -8
- package/lib/mjs/hooks/useAnswerResults.js +6 -18
- package/lib/mjs/hooks/useCioPia.js +3 -1
- package/lib/mjs/hooks/useSuggestedQuestions.js +8 -4
- package/lib/mjs/index.js +2 -0
- package/lib/mjs/styles.css +0 -1
- package/lib/mjs/utils/transformers.js +19 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/CioPia/CioPia.d.ts +5 -0
- package/lib/types/components/icons/QuestionIcon.d.ts +2 -0
- package/lib/types/components/icons/SendIcon.d.ts +2 -0
- package/lib/types/components/icons/SparklesIcon.d.ts +2 -0
- package/lib/types/components/icons/index.d.ts +3 -0
- package/lib/types/errors.d.ts +12 -0
- package/lib/types/hooks/mocks/agent.d.ts +1 -1
- package/lib/types/hooks/mocks/types.d.ts +2 -0
- package/lib/types/hooks/useAnswerResults.d.ts +2 -2
- package/lib/types/hooks/useCioPia.d.ts +5 -0
- package/lib/types/hooks/useSuggestedQuestions.d.ts +2 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/utils/transformers.d.ts +8 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
const fetchSuggestedQuestions = async ({ client, itemId, variationId, threadId, parameters, }) => {
|
|
2
|
+
const fetchSuggestedQuestions = async ({ client, itemId, variationId, threadId, parameters, requestParameters, }) => {
|
|
3
3
|
const response = await client.agent.getSuggestedQuestions({
|
|
4
4
|
itemId,
|
|
5
5
|
variationId,
|
|
6
6
|
threadId,
|
|
7
7
|
parameters,
|
|
8
|
+
requestParameters,
|
|
8
9
|
});
|
|
9
10
|
return response.questions;
|
|
10
11
|
};
|
|
11
|
-
export default function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, parameters, }) {
|
|
12
|
+
export default function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, parameters, requestParameters, }) {
|
|
12
13
|
const [questions, setQuestions] = useState([]);
|
|
13
14
|
const [isLoading, setIsLoading] = useState(false);
|
|
14
15
|
const [error, setError] = useState(null);
|
|
16
|
+
// Serialize to a primitive so an object-literal prop doesn't retrigger the auto-fetch effect each render.
|
|
17
|
+
const requestParametersKey = JSON.stringify(requestParameters);
|
|
15
18
|
const fetchResult = useCallback(() => {
|
|
16
19
|
if (!cioClient)
|
|
17
20
|
return;
|
|
@@ -23,6 +26,7 @@ export default function useSuggestedQuestions({ itemId, variationId, threadId, c
|
|
|
23
26
|
variationId,
|
|
24
27
|
threadId,
|
|
25
28
|
parameters,
|
|
29
|
+
requestParameters,
|
|
26
30
|
})
|
|
27
31
|
.then((fetchedQuestions) => {
|
|
28
32
|
setQuestions(fetchedQuestions);
|
|
@@ -34,8 +38,8 @@ export default function useSuggestedQuestions({ itemId, variationId, threadId, c
|
|
|
34
38
|
.finally(() => {
|
|
35
39
|
setIsLoading(false);
|
|
36
40
|
});
|
|
37
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- primitive
|
|
38
|
-
}, [cioClient, itemId, variationId, threadId, parameters?.numResults]);
|
|
41
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- primitive deps prevent refetch loop
|
|
42
|
+
}, [cioClient, itemId, variationId, threadId, parameters?.numResults, requestParametersKey]);
|
|
39
43
|
useEffect(() => {
|
|
40
44
|
fetchResult();
|
|
41
45
|
}, [fetchResult]);
|
package/lib/mjs/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import CioPia from './components/CioPia';
|
|
|
3
3
|
export { default as CioPia } from './components/CioPia';
|
|
4
4
|
// Utilities
|
|
5
5
|
export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
|
|
6
|
+
// Errors
|
|
7
|
+
export { AgentRequestError } from './errors';
|
|
6
8
|
// Default
|
|
7
9
|
export * from './types';
|
|
8
10
|
export default CioPia;
|
package/lib/mjs/styles.css
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
@import '@constructor-io/constructorio-ui-components/styles.css';
|
|
2
|
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap');
|
|
3
2
|
@import './components/SuggestedQuestion/SuggestedQuestionStyles.css';
|
|
4
3
|
@import './components/SuggestedQuestionsContainer/SuggestedQuestionsContainerStyles.css';
|
|
5
4
|
@import './components/Input/InputStyles.css';
|
|
@@ -38,3 +38,22 @@ export function transformResultItem(resultItem, formatImageUrl) {
|
|
|
38
38
|
...otherFields,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Pulls the product results out of an answers response and converts them to Items.
|
|
43
|
+
*
|
|
44
|
+
* Returns `null` rather than an empty array whenever there is nothing to render, so callers
|
|
45
|
+
* can treat "no products" as a single case.
|
|
46
|
+
*/
|
|
47
|
+
export function extractAndTransformItems(data, formatImageUrl) {
|
|
48
|
+
if (!data?.item_results?.response?.results) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const { results } = data.item_results.response;
|
|
52
|
+
if (!Array.isArray(results) || results.length === 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const transformedItems = results
|
|
56
|
+
.map((item) => transformResultItem(item, formatImageUrl))
|
|
57
|
+
.filter((item) => item !== null);
|
|
58
|
+
return transformedItems.length > 0 ? transformedItems : null;
|
|
59
|
+
}
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '2.10.
|
|
1
|
+
export default '2.10.4';
|
|
@@ -29,5 +29,10 @@ export interface CioPiaProps extends IncludeRenderProps<CioPiaRenderProps>, Incl
|
|
|
29
29
|
translations?: Translations;
|
|
30
30
|
/** Parameters for the suggested questions request. */
|
|
31
31
|
suggestedQuestionsParameters?: SuggestedQuestionsParameters;
|
|
32
|
+
/**
|
|
33
|
+
* Extra query parameters appended to PIA API requests (e.g. `ef-*` test cell params).
|
|
34
|
+
* Define outside the component or wrap with useMemo to avoid unnecessary re-renders.
|
|
35
|
+
*/
|
|
36
|
+
parameters?: Record<string, string | number | boolean>;
|
|
32
37
|
}
|
|
33
38
|
export default function CioPia(props: CioPiaProps): React.JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a Constructor agent request returns a non-2xx response.
|
|
3
|
+
*
|
|
4
|
+
* `status` is the HTTP status code, so callers can act on the kind of failure instead of
|
|
5
|
+
* parsing the message. A 422 means the request itself was rejected as unsuitable, a 429
|
|
6
|
+
* means rate limiting, and anything 500 or above means the service failed and a retry may
|
|
7
|
+
* succeed. This is the error that arrives in `CioPiaRenderProps.error` when a request fails.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AgentRequestError extends Error {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
constructor(status: number);
|
|
12
|
+
}
|
|
@@ -3,7 +3,7 @@ import { QuestionResponse, GetSuggestedQuestionsProps, GetAnswerResultsStreamPro
|
|
|
3
3
|
declare class MockAgent {
|
|
4
4
|
options: ConstructorClientOptions;
|
|
5
5
|
constructor(options: ConstructorClientOptions);
|
|
6
|
-
getSuggestedQuestions({ itemId, variationId, threadId, parameters, }: GetSuggestedQuestionsProps): Promise<QuestionResponse>;
|
|
6
|
+
getSuggestedQuestions({ itemId, variationId, threadId, parameters, requestParameters, }: GetSuggestedQuestionsProps): Promise<QuestionResponse>;
|
|
7
7
|
getAnswerResults({ itemId, variationId, threadId, question, parameters, }: GetAnswerResultsProps): Promise<GetAnswerResultsResponse>;
|
|
8
8
|
getAnswerResultsStream({ itemId, threadId, variationId, question, parameters, onStart, onMessage, onEnd, }: GetAnswerResultsStreamProps): Promise<void>;
|
|
9
9
|
}
|
|
@@ -18,6 +18,8 @@ export type GetSuggestedQuestionsProps = {
|
|
|
18
18
|
/** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
|
|
19
19
|
threadId?: string;
|
|
20
20
|
parameters?: SuggestedQuestionsParameters;
|
|
21
|
+
/** Extra query parameters appended verbatim to the request (e.g. `ef-*` test cell params). */
|
|
22
|
+
requestParameters?: Record<string, string | number | boolean>;
|
|
21
23
|
};
|
|
22
24
|
export interface Question {
|
|
23
25
|
value: string;
|
|
@@ -6,7 +6,7 @@ export interface UseAnswerResultsProps {
|
|
|
6
6
|
variationId?: string;
|
|
7
7
|
threadId?: string;
|
|
8
8
|
cioClient: MockConstructorIOClient;
|
|
9
|
-
parameters?: Record<string,
|
|
9
|
+
parameters?: Record<string, string | number | boolean>;
|
|
10
10
|
formatImageUrl?: Formatters['formatImageUrl'];
|
|
11
11
|
}
|
|
12
12
|
export interface UseAnswerResultsReturn {
|
|
@@ -16,4 +16,4 @@ export interface UseAnswerResultsReturn {
|
|
|
16
16
|
error: Error | null;
|
|
17
17
|
getAnswer: (question: string) => void;
|
|
18
18
|
}
|
|
19
|
-
export default function useAnswerResults({ itemId, variationId, threadId, cioClient, formatImageUrl, }: UseAnswerResultsProps): UseAnswerResultsReturn;
|
|
19
|
+
export default function useAnswerResults({ itemId, variationId, threadId, cioClient, parameters, formatImageUrl, }: UseAnswerResultsProps): UseAnswerResultsReturn;
|
|
@@ -10,6 +10,11 @@ export interface UseCioPiaProps {
|
|
|
10
10
|
threadId?: string;
|
|
11
11
|
cioClient?: MockConstructorIOClient;
|
|
12
12
|
suggestedQuestionsParameters?: SuggestedQuestionsParameters;
|
|
13
|
+
/**
|
|
14
|
+
* Extra query parameters appended to PIA API requests (e.g. `ef-*` test cell params).
|
|
15
|
+
* Define outside the component or wrap with useMemo to avoid unnecessary re-renders.
|
|
16
|
+
*/
|
|
17
|
+
parameters?: Record<string, string | number | boolean>;
|
|
13
18
|
/** Define outside the component or wrap with useCallback to avoid unnecessary re-renders. */
|
|
14
19
|
formatImageUrl?: Formatters['formatImageUrl'];
|
|
15
20
|
}
|
|
@@ -6,6 +6,7 @@ export interface UseSuggestedQuestionsProps {
|
|
|
6
6
|
threadId?: string;
|
|
7
7
|
cioClient?: MockConstructorIOClient;
|
|
8
8
|
parameters?: SuggestedQuestionsParameters;
|
|
9
|
+
requestParameters?: Record<string, string | number | boolean>;
|
|
9
10
|
}
|
|
10
11
|
export interface UseSuggestedQuestionsReturn {
|
|
11
12
|
data: Array<Question>;
|
|
@@ -13,4 +14,4 @@ export interface UseSuggestedQuestionsReturn {
|
|
|
13
14
|
error: Error | null;
|
|
14
15
|
getSuggestedQuestions: () => void;
|
|
15
16
|
}
|
|
16
|
-
export default function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, parameters, }: UseSuggestedQuestionsProps): UseSuggestedQuestionsReturn;
|
|
17
|
+
export default function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, parameters, requestParameters, }: UseSuggestedQuestionsProps): UseSuggestedQuestionsReturn;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export { default as CioPia } from './components/CioPia';
|
|
|
3
3
|
export type { CioPiaProps } from './components/CioPia';
|
|
4
4
|
export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
|
|
5
5
|
export type { RenderMarkdownOptions, SanitizeOptions } from './utils/contentTransformers';
|
|
6
|
+
export { AgentRequestError } from './errors';
|
|
6
7
|
export * from './types';
|
|
7
8
|
export default CioPia;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { Nullable } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
-
import { ApiItem, Formatters, Item } from '../types';
|
|
2
|
+
import { ApiItem, Formatters, GetAnswerResultsResponse, Item } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Converts a raw ApiItem from the Get Answers API response into an Item object
|
|
5
5
|
* that can be used in the Carousel component.
|
|
6
6
|
*/
|
|
7
7
|
export declare function transformResultItem(resultItem: ApiItem, formatImageUrl?: Formatters['formatImageUrl']): Nullable<Item>;
|
|
8
|
+
/**
|
|
9
|
+
* Pulls the product results out of an answers response and converts them to Items.
|
|
10
|
+
*
|
|
11
|
+
* Returns `null` rather than an empty array whenever there is nothing to render, so callers
|
|
12
|
+
* can treat "no products" as a single case.
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractAndTransformItems(data: Nullable<GetAnswerResultsResponse>, formatImageUrl?: Formatters['formatImageUrl']): Array<Item> | null;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.10.
|
|
1
|
+
declare const _default: "2.10.4";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-ui-pia",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.4",
|
|
4
4
|
"description": "Constructor.io AI Product Insights Agent UI library for web applications",
|
|
5
5
|
"author": "Constructor.io Corporation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"prepare": "husky"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@constructor-io/constructorio-client-javascript": "^2.
|
|
73
|
+
"@constructor-io/constructorio-client-javascript": "^2.91.0",
|
|
74
74
|
"@constructor-io/constructorio-ui-components": "^1.5.0",
|
|
75
75
|
"react": ">=16.12.0",
|
|
76
76
|
"react-dom": ">=16.12.0",
|