@constructor-io/constructorio-ui-asa 1.1.0 → 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.
@@ -32,6 +32,8 @@ function useAsaResults() {
32
32
  trackingRef.current = tracking;
33
33
  const callbacksRef = (0, react_1.useRef)(callbacks);
34
34
  callbacksRef.current = callbacks;
35
+ const staticRequestConfigsRef = (0, react_1.useRef)(staticRequestConfigs);
36
+ staticRequestConfigsRef.current = staticRequestConfigs;
35
37
  const nextMessageId = (0, react_1.useCallback)(() => {
36
38
  idCounterRef.current += 1;
37
39
  return `msg-${idCounterRef.current}-${Date.now()}`;
@@ -61,7 +63,14 @@ function useAsaResults() {
61
63
  setIsStreaming(true);
62
64
  isStreamingRef.current = true;
63
65
  killSwitchRef.current = false;
64
- const stream = cioClient.agent.getAgentResultsStream(intent, Object.assign({ domain }, (threadIdRef.current && { threadId: threadIdRef.current })));
66
+ // `intent` is passed as the first argument and `threadId` is managed per-stream
67
+ // below, so both are stripped here. Everything else configured on the provider
68
+ // (filters, guard, numResultsPerEvent, numResultEvents, qsParam,
69
+ // preFilterExpression, fmtOptions, ...) is forwarded to the agent as-is.
70
+ const agentParams = Object.assign({}, staticRequestConfigsRef.current);
71
+ delete agentParams.intent;
72
+ delete agentParams.threadId;
73
+ const stream = cioClient.agent.getAgentResultsStream(intent, Object.assign(Object.assign(Object.assign({}, agentParams), { domain }), (threadIdRef.current && { threadId: threadIdRef.current })));
65
74
  const reader = stream.getReader();
66
75
  readerRef.current = reader;
67
76
  // Mutable per-stream state kept on an object so the closures below don't capture
@@ -5,8 +5,18 @@ const react_1 = require("react");
5
5
  exports.AsaContext = (0, react_1.createContext)(null);
6
6
  exports.AsaContext.displayName = 'AsaContext';
7
7
  /**
8
- * React Hook to access state provided by CioAsa provider.
9
- * Note: Should only be used by components nested under a CioAsa provider
8
+ * React Hook to access the state provided by the CioAsa provider.
9
+ *
10
+ * Returns `null` when called from a component that is not nested under a
11
+ * `CioAsaProvider`, so guard the result before reading from it:
12
+ *
13
+ * ```tsx
14
+ * const context = useCioAsaContext();
15
+ * const tracking = useAsaTracking({
16
+ * tracker: context?.cioClient?.tracker ?? undefined,
17
+ * section: context?.section,
18
+ * });
19
+ * ```
10
20
  */
11
21
  function useCioAsaContext() {
12
22
  return (0, react_1.useContext)(exports.AsaContext);
package/lib/cjs/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ConstructorIOClient = exports.normalizeItemToProduct = exports.useAsaTracking = exports.useAsaResults = exports.Button = exports.ResultsBlock = exports.Chat = exports.CioAsaProvider = void 0;
6
+ exports.ConstructorIOClient = exports.normalizeItemToProduct = exports.useCioAsaContext = exports.useAsaTracking = exports.useAsaResults = exports.Button = exports.ResultsBlock = exports.Chat = exports.CioAsaProvider = void 0;
7
7
  // Components
8
8
  var CioAsaProvider_1 = require("./components/CioAsaProvider/CioAsaProvider");
9
9
  Object.defineProperty(exports, "CioAsaProvider", { enumerable: true, get: function () { return __importDefault(CioAsaProvider_1).default; } });
@@ -18,6 +18,8 @@ var useAsaResults_1 = require("./hooks/useAsaResults");
18
18
  Object.defineProperty(exports, "useAsaResults", { enumerable: true, get: function () { return __importDefault(useAsaResults_1).default; } });
19
19
  var useAsaTracking_1 = require("./hooks/useAsaTracking");
20
20
  Object.defineProperty(exports, "useAsaTracking", { enumerable: true, get: function () { return __importDefault(useAsaTracking_1).default; } });
21
+ var useCioAsaContext_1 = require("./hooks/useCioAsaContext");
22
+ Object.defineProperty(exports, "useCioAsaContext", { enumerable: true, get: function () { return __importDefault(useCioAsaContext_1).default; } });
21
23
  // Utils
22
24
  var productNormalizer_1 = require("./utils/productNormalizer");
23
25
  Object.defineProperty(exports, "normalizeItemToProduct", { enumerable: true, get: function () { return productNormalizer_1.normalizeItemToProduct; } });
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.1.0';
3
+ exports.default = '1.2.0';
@@ -28,6 +28,8 @@ export default function useAsaResults() {
28
28
  trackingRef.current = tracking;
29
29
  const callbacksRef = useRef(callbacks);
30
30
  callbacksRef.current = callbacks;
31
+ const staticRequestConfigsRef = useRef(staticRequestConfigs);
32
+ staticRequestConfigsRef.current = staticRequestConfigs;
31
33
  const nextMessageId = useCallback(() => {
32
34
  idCounterRef.current += 1;
33
35
  return `msg-${idCounterRef.current}-${Date.now()}`;
@@ -56,7 +58,15 @@ export default function useAsaResults() {
56
58
  setIsStreaming(true);
57
59
  isStreamingRef.current = true;
58
60
  killSwitchRef.current = false;
61
+ // `intent` is passed as the first argument and `threadId` is managed per-stream
62
+ // below, so both are stripped here. Everything else configured on the provider
63
+ // (filters, guard, numResultsPerEvent, numResultEvents, qsParam,
64
+ // preFilterExpression, fmtOptions, ...) is forwarded to the agent as-is.
65
+ const agentParams = { ...staticRequestConfigsRef.current };
66
+ delete agentParams.intent;
67
+ delete agentParams.threadId;
59
68
  const stream = cioClient.agent.getAgentResultsStream(intent, {
69
+ ...agentParams,
60
70
  domain,
61
71
  ...(threadIdRef.current && { threadId: threadIdRef.current }),
62
72
  });
@@ -2,8 +2,18 @@ import { createContext, useContext } from 'react';
2
2
  export const AsaContext = createContext(null);
3
3
  AsaContext.displayName = 'AsaContext';
4
4
  /**
5
- * React Hook to access state provided by CioAsa provider.
6
- * Note: Should only be used by components nested under a CioAsa provider
5
+ * React Hook to access the state provided by the CioAsa provider.
6
+ *
7
+ * Returns `null` when called from a component that is not nested under a
8
+ * `CioAsaProvider`, so guard the result before reading from it:
9
+ *
10
+ * ```tsx
11
+ * const context = useCioAsaContext();
12
+ * const tracking = useAsaTracking({
13
+ * tracker: context?.cioClient?.tracker ?? undefined,
14
+ * section: context?.section,
15
+ * });
16
+ * ```
7
17
  */
8
18
  export function useCioAsaContext() {
9
19
  return useContext(AsaContext);
package/lib/mjs/index.js CHANGED
@@ -6,6 +6,7 @@ export { default as Button } from './components/Button/Button';
6
6
  // Hooks
7
7
  export { default as useAsaResults } from './hooks/useAsaResults';
8
8
  export { default as useAsaTracking } from './hooks/useAsaTracking';
9
+ export { default as useCioAsaContext } from './hooks/useCioAsaContext';
9
10
  // Utils
10
11
  export { normalizeItemToProduct } from './utils/productNormalizer';
11
12
  // Re-exported client value from the JS client (used to construct/type a cioClient)
@@ -1 +1 @@
1
- export default '1.1.0';
1
+ export default '1.2.0';
@@ -1,9 +1,19 @@
1
1
  /// <reference types="react" />
2
- import { AsaContextValue } from '../types';
2
+ import { AsaContextValue, Nullable } from '../types';
3
3
  export declare const AsaContext: import("react").Context<AsaContextValue | null>;
4
4
  /**
5
- * React Hook to access state provided by CioAsa provider.
6
- * Note: Should only be used by components nested under a CioAsa provider
5
+ * React Hook to access the state provided by the CioAsa provider.
6
+ *
7
+ * Returns `null` when called from a component that is not nested under a
8
+ * `CioAsaProvider`, so guard the result before reading from it:
9
+ *
10
+ * ```tsx
11
+ * const context = useCioAsaContext();
12
+ * const tracking = useAsaTracking({
13
+ * tracker: context?.cioClient?.tracker ?? undefined,
14
+ * section: context?.section,
15
+ * });
16
+ * ```
7
17
  */
8
- export declare function useCioAsaContext(): AsaContextValue;
18
+ export declare function useCioAsaContext(): Nullable<AsaContextValue>;
9
19
  export default useCioAsaContext;
@@ -7,6 +7,7 @@ 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
9
  export { default as useAsaTracking } from './hooks/useAsaTracking';
10
+ export { default as useCioAsaContext } from './hooks/useCioAsaContext';
10
11
  export type { UseAsaTrackingProps, UseAsaTrackingReturn } from './hooks/useAsaTracking';
11
12
  export { normalizeItemToProduct } from './utils/productNormalizer';
12
13
  export type { Product, NormalizeOptions } from './utils/productNormalizer';
@@ -1,2 +1,2 @@
1
- declare const _default: "1.1.0";
1
+ declare const _default: "1.2.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.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Constructor.io AI Shopping Agent UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",