@constructor-io/constructorio-ui-pia 2.10.1 → 2.10.3
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 +40 -40
- package/lib/cjs/components/CioPia/CioPia.js +3 -2
- package/lib/cjs/components/Input/Input.js +21 -17
- package/lib/cjs/components/PiaConversation/PiaConversation.js +1 -1
- package/lib/cjs/components/PiaConversation/PiaModal.js +1 -1
- 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/utils/transformers.js +22 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioPia/CioPia.js +3 -2
- package/lib/mjs/components/Input/Input.js +22 -18
- package/lib/mjs/components/PiaConversation/PiaConversation.js +1 -1
- package/lib/mjs/components/PiaConversation/PiaModal.js +1 -1
- 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/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/Input/Input.d.ts +4 -2
- 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/types.d.ts +11 -0
- package/lib/types/utils/transformers.d.ts +8 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
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 class AgentRequestError extends Error {
|
|
10
|
+
status;
|
|
11
|
+
constructor(status) {
|
|
12
|
+
super(`Request failed with status ${status}`);
|
|
13
|
+
this.name = 'AgentRequestError';
|
|
14
|
+
this.status = status;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AgentRequestError } from '../../errors';
|
|
1
2
|
// Create URL for PIA API
|
|
2
3
|
function createAgentUrl({ itemId, threadId, variationId, question, isStreaming = false, options, parameters = {}, }) {
|
|
3
4
|
const { apiKey, agentServiceUrl, clientId, sessionId, userId, segments, version } = options;
|
|
@@ -54,7 +55,7 @@ class MockAgent {
|
|
|
54
55
|
constructor(options) {
|
|
55
56
|
this.options = options;
|
|
56
57
|
}
|
|
57
|
-
async getSuggestedQuestions({ itemId, variationId, threadId, parameters = {}, }) {
|
|
58
|
+
async getSuggestedQuestions({ itemId, variationId, threadId, parameters = {}, requestParameters = {}, }) {
|
|
58
59
|
if (!itemId)
|
|
59
60
|
throw new Error('Item ID is required');
|
|
60
61
|
if (!this.options.apiKey)
|
|
@@ -64,18 +65,20 @@ class MockAgent {
|
|
|
64
65
|
variationId,
|
|
65
66
|
threadId,
|
|
66
67
|
options: this.options,
|
|
67
|
-
parameters: mapSuggestedQuestionsParams(parameters),
|
|
68
|
+
parameters: { ...requestParameters, ...mapSuggestedQuestionsParams(parameters) },
|
|
68
69
|
});
|
|
69
70
|
try {
|
|
70
71
|
const response = await fetch(url);
|
|
71
72
|
if (!response.ok)
|
|
72
|
-
throw new
|
|
73
|
+
throw new AgentRequestError(response.status);
|
|
73
74
|
const data = await response.json();
|
|
74
75
|
return data;
|
|
75
76
|
}
|
|
76
77
|
catch (error) {
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
// Rethrow untouched so the status code and the original stack survive.
|
|
79
|
+
if (error instanceof Error)
|
|
80
|
+
throw error;
|
|
81
|
+
throw new Error(String(error));
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
async getAnswerResults({ itemId, variationId, threadId, question, parameters = {}, }) {
|
|
@@ -96,13 +99,15 @@ class MockAgent {
|
|
|
96
99
|
try {
|
|
97
100
|
const response = await fetch(url);
|
|
98
101
|
if (!response.ok)
|
|
99
|
-
throw new
|
|
102
|
+
throw new AgentRequestError(response.status);
|
|
100
103
|
const data = await response.json();
|
|
101
104
|
return data;
|
|
102
105
|
}
|
|
103
106
|
catch (error) {
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
// Rethrow untouched so the status code and the original stack survive.
|
|
108
|
+
if (error instanceof Error)
|
|
109
|
+
throw error;
|
|
110
|
+
throw new Error(String(error));
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
async getAnswerResultsStream({ itemId, threadId, variationId, question, parameters, onStart, onMessage, onEnd, }) {
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
if (!data?.item_results?.response?.results) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const { results } = data.item_results.response;
|
|
8
|
-
if (!Array.isArray(results) || results.length === 0) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
const transformedItems = results
|
|
12
|
-
.map((item) => transformResultItem(item, formatImageUrl))
|
|
13
|
-
.filter((item) => item !== null);
|
|
14
|
-
return transformedItems.length > 0 ? transformedItems : null;
|
|
15
|
-
};
|
|
16
|
-
const fetchAnswerResults = async ({ client, itemId, question, variationId, threadId, }) => {
|
|
2
|
+
import { extractAndTransformItems } from '../utils/transformers';
|
|
3
|
+
const fetchAnswerResults = async ({ client, itemId, question, variationId, threadId, parameters, }) => {
|
|
17
4
|
const response = await client.agent.getAnswerResults({
|
|
18
5
|
itemId,
|
|
19
6
|
variationId,
|
|
20
7
|
threadId,
|
|
21
8
|
question,
|
|
9
|
+
parameters,
|
|
22
10
|
});
|
|
23
11
|
return response;
|
|
24
12
|
};
|
|
25
|
-
export default function useAnswerResults({ itemId, variationId, threadId, cioClient, formatImageUrl, }) {
|
|
13
|
+
export default function useAnswerResults({ itemId, variationId, threadId, cioClient, parameters, formatImageUrl, }) {
|
|
26
14
|
const [answerResults, setAnswerResults] = useState(null);
|
|
27
15
|
const [isLoading, setIsLoading] = useState(false);
|
|
28
16
|
const [error, setError] = useState(null);
|
|
@@ -33,7 +21,7 @@ export default function useAnswerResults({ itemId, variationId, threadId, cioCli
|
|
|
33
21
|
setIsLoading(true);
|
|
34
22
|
setError(null);
|
|
35
23
|
setAnswerResults(null);
|
|
36
|
-
fetchAnswerResults({ client: cioClient, itemId, question, variationId, threadId })
|
|
24
|
+
fetchAnswerResults({ client: cioClient, itemId, question, variationId, threadId, parameters })
|
|
37
25
|
.then((fetchedAnswerResults) => {
|
|
38
26
|
setAnswerResults(fetchedAnswerResults);
|
|
39
27
|
setError(null);
|
|
@@ -45,7 +33,7 @@ export default function useAnswerResults({ itemId, variationId, threadId, cioCli
|
|
|
45
33
|
.finally(() => {
|
|
46
34
|
setIsLoading(false);
|
|
47
35
|
});
|
|
48
|
-
}, [cioClient, itemId, variationId, threadId]);
|
|
36
|
+
}, [cioClient, itemId, variationId, threadId, parameters]);
|
|
49
37
|
return {
|
|
50
38
|
data: answerResults,
|
|
51
39
|
items,
|
|
@@ -4,7 +4,7 @@ import useAnswerResults from './useAnswerResults';
|
|
|
4
4
|
import useSuggestedQuestions from './useSuggestedQuestions';
|
|
5
5
|
import version from '../version';
|
|
6
6
|
export default function useCioPia(props) {
|
|
7
|
-
const { apiKey, itemId, variationId, threadId: providedThreadId, cioClient: providedClient, suggestedQuestionsParameters, formatImageUrl, } = props;
|
|
7
|
+
const { apiKey, itemId, variationId, threadId: providedThreadId, cioClient: providedClient, suggestedQuestionsParameters, parameters, formatImageUrl, } = props;
|
|
8
8
|
const [generatedThreadId] = useState(() => crypto.randomUUID());
|
|
9
9
|
const threadId = providedThreadId || generatedThreadId;
|
|
10
10
|
const client = useMemo(() => {
|
|
@@ -22,12 +22,14 @@ export default function useCioPia(props) {
|
|
|
22
22
|
threadId,
|
|
23
23
|
cioClient: client,
|
|
24
24
|
parameters: suggestedQuestionsParameters,
|
|
25
|
+
requestParameters: parameters,
|
|
25
26
|
});
|
|
26
27
|
const answers = useAnswerResults({
|
|
27
28
|
itemId,
|
|
28
29
|
variationId,
|
|
29
30
|
threadId,
|
|
30
31
|
cioClient: client,
|
|
32
|
+
parameters,
|
|
31
33
|
formatImageUrl,
|
|
32
34
|
});
|
|
33
35
|
return {
|
|
@@ -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;
|
|
@@ -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.3';
|
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
|
|
3
|
+
import { InputRenderProps, Translations } from '../../types';
|
|
3
4
|
interface InputProps {
|
|
4
5
|
value?: string;
|
|
5
6
|
disabled?: boolean;
|
|
@@ -8,6 +9,7 @@ interface InputProps {
|
|
|
8
9
|
onSubmit: (value: string) => void;
|
|
9
10
|
onFocus?: () => void;
|
|
10
11
|
translations?: Translations;
|
|
12
|
+
componentOverride?: ComponentOverrideProps<InputRenderProps>;
|
|
11
13
|
}
|
|
12
|
-
declare function Input({ value: providedValue, placeholder, disabled, onSubmit, onFocus, translations, }: InputProps): React.JSX.Element;
|
|
14
|
+
declare function Input({ value: providedValue, placeholder, disabled, onSubmit, onFocus, translations, componentOverride, }: InputProps): React.JSX.Element;
|
|
13
15
|
export default Input;
|
|
@@ -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;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -146,6 +146,16 @@ export interface FeedbackRenderProps {
|
|
|
146
146
|
export interface LoadingRenderProps {
|
|
147
147
|
skeleton: ReactNode;
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Render props passed to a custom Input override.
|
|
151
|
+
*/
|
|
152
|
+
export interface InputRenderProps {
|
|
153
|
+
disabled: boolean;
|
|
154
|
+
placeholder: string;
|
|
155
|
+
onSubmit: (value: string) => void;
|
|
156
|
+
onFocus?: () => void;
|
|
157
|
+
translations?: Translations;
|
|
158
|
+
}
|
|
149
159
|
/**
|
|
150
160
|
* Component overrides for CioPia.
|
|
151
161
|
* Allows customization of sub-components via reactNode or render props functions.
|
|
@@ -153,6 +163,7 @@ export interface LoadingRenderProps {
|
|
|
153
163
|
export interface CioPiaComponentOverrides extends ComponentOverrideProps<CioPiaRenderProps> {
|
|
154
164
|
carousel?: CarouselOverrides<Item>;
|
|
155
165
|
answer?: ComponentOverrideProps<AnswerRenderProps>;
|
|
166
|
+
input?: ComponentOverrideProps<InputRenderProps>;
|
|
156
167
|
suggestedQuestions?: ComponentOverrideProps<SuggestedQuestionsRenderProps>;
|
|
157
168
|
disclaimer?: ComponentOverrideProps<DisclaimerRenderProps>;
|
|
158
169
|
feedback?: ComponentOverrideProps<FeedbackRenderProps>;
|
|
@@ -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.3";
|
|
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.3",
|
|
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",
|