@box/box-ai-agent-selector 0.30.0 → 0.31.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.
@@ -1,27 +1,28 @@
1
- import { useState as d, useCallback as m, useEffect as f } from "react";
2
- import { BoxAiAgentSelector as I } from "./box-ai-agent-selector.js";
1
+ import { useState as I, useCallback as m, useEffect as f } from "react";
2
+ import { BoxAiAgentSelector as L } from "./box-ai-agent-selector.js";
3
3
  import { LOGGER_BASE_CONFIG as a, LOGGER_TARGET as l } from "./constants.js";
4
4
  import { ACTIONS as S } from "./contexts/actions.js";
5
- import { useAgentsDispatch as L, useAgents as U } from "./contexts/context.js";
5
+ import { useAgentsDispatch as U, useAgents as x } from "./contexts/context.js";
6
6
  import { R as r } from "../../chunks/types.js";
7
- import { jsx as x } from "react/jsx-runtime";
8
- function j({
7
+ import { jsx as D } from "react/jsx-runtime";
8
+ function k({
9
9
  fetcher: u,
10
10
  hostAppName: R,
11
11
  onSelectAgent: i,
12
12
  recordAction: T,
13
13
  requestState: s,
14
14
  disabled: G,
15
- shouldHideAgentSelectorOnLoad: C,
16
- triggerChipClassName: h,
17
- contentClassName: p,
18
- variant: O = "modal"
15
+ onAgentsListOpen: C,
16
+ shouldHideAgentSelectorOnLoad: h,
17
+ triggerChipClassName: p,
18
+ contentClassName: O,
19
+ variant: N = "modal"
19
20
  }) {
20
- const e = L(), {
21
+ const e = U(), {
21
22
  agents: A,
22
23
  requestState: E,
23
24
  selectedAgent: n
24
- } = U(), [N, _] = d(!1), o = m((t) => {
25
+ } = x(), [d, _] = I(!1), o = m((t) => {
25
26
  T && (t.data ?? (t.data = {}), t.data.hostAppName = R, T(t));
26
27
  }, [R, T]), c = m(async () => {
27
28
  e({
@@ -61,19 +62,20 @@ function j({
61
62
  }));
62
63
  }, [e, E, s]), f(() => {
63
64
  i && i(n);
64
- }, [i, n]), C && !N || E === r.SUCCESS && A.length <= 1 ? null : /* @__PURE__ */ x(I, {
65
+ }, [i, n]), h && !d || E === r.SUCCESS && A.length <= 1 ? null : /* @__PURE__ */ D(L, {
65
66
  agents: A,
66
- contentClassName: p,
67
+ contentClassName: O,
67
68
  disabled: G,
69
+ onAgentsListOpen: C,
68
70
  onErrorAction: c,
69
71
  recordAction: o,
70
72
  requestState: E,
71
73
  selectedAgent: n,
72
- triggerChipClassName: h,
73
- variant: O
74
+ triggerChipClassName: p,
75
+ variant: N
74
76
  });
75
77
  }
76
78
  export {
77
- j as BoxAiAgentSelectorWithApi,
78
- j as default
79
+ k as BoxAiAgentSelectorWithApi,
80
+ k as default
79
81
  };
@@ -1,52 +1,53 @@
1
- import { useFullTextTooltip as H, FilterChip as c, Popover as d, Tooltip as J, Status as X, LoadingIndicator as Z, SmallList as $, Button as q } from "@box/blueprint-web";
2
- import { AlertBadge as tt } from "@box/blueprint-web-assets/icons/Fill";
1
+ import { useFullTextTooltip as X, FilterChip as c, Popover as d, Tooltip as Z, Status as $, LoadingIndicator as q, SmallList as tt, Button as et } from "@box/blueprint-web";
2
+ import { AlertBadge as at } from "@box/blueprint-web-assets/icons/Fill";
3
3
  import m from "clsx";
4
- import { useState as x, useRef as et, useEffect as at, useCallback as f } from "react";
5
- import { useIntl as rt } from "react-intl";
6
- import { BoxAiAgent as ot } from "./box-ai-agent.js";
4
+ import { useState as B, useRef as rt, useEffect as ot, useCallback as f } from "react";
5
+ import { useIntl as nt } from "react-intl";
6
+ import { BoxAiAgent as st } from "./box-ai-agent.js";
7
7
  import { LOGGER_BASE_CONFIG as E, LOGGER_ACTION_CLICK as S, LOGGER_TARGET as T } from "./constants.js";
8
- import { ACTIONS as nt } from "./contexts/actions.js";
9
- import { useAgentsDispatch as st } from "./contexts/context.js";
8
+ import { ACTIONS as it } from "./contexts/actions.js";
9
+ import { useAgentsDispatch as lt } from "./contexts/context.js";
10
10
  import s from "./messages.js";
11
11
  import { R } from "../../chunks/types.js";
12
12
  import { jsx as e, jsxs as I } from "react/jsx-runtime";
13
- import '../../styles/box-ai-agent-selector.css';const it = "_agentSelector_prbzs_1", lt = "_agentStatus_prbzs_4", pt = "_agentLoader_prbzs_18", gt = "_agentError_prbzs_21", ct = "_triggerChip_prbzs_24", dt = "_agentLabel_prbzs_30", mt = "_dropdownIndicator_prbzs_36", ft = "_sidebar_prbzs_51", _t = "_agentListItemIcon_prbzs_64", Lt = "_agentListContainer_prbzs_69", ut = "_agentListRetryButton_prbzs_99", a = {
14
- agentSelector: it,
15
- agentStatus: lt,
16
- agentLoader: pt,
17
- agentError: gt,
18
- triggerChip: ct,
19
- agentLabel: dt,
20
- dropdownIndicator: mt,
21
- sidebar: ft,
22
- agentListItemIcon: _t,
23
- agentListContainer: Lt,
24
- agentListRetryButton: ut
13
+ import '../../styles/box-ai-agent-selector.css';const pt = "_agentSelector_prbzs_1", gt = "_agentStatus_prbzs_4", ct = "_agentLoader_prbzs_18", dt = "_agentError_prbzs_21", mt = "_triggerChip_prbzs_24", ft = "_agentLabel_prbzs_30", _t = "_dropdownIndicator_prbzs_36", Lt = "_sidebar_prbzs_51", ht = "_agentListItemIcon_prbzs_64", ut = "_agentListContainer_prbzs_69", Ct = "_agentListRetryButton_prbzs_99", a = {
14
+ agentSelector: pt,
15
+ agentStatus: gt,
16
+ agentLoader: ct,
17
+ agentError: dt,
18
+ triggerChip: mt,
19
+ agentLabel: ft,
20
+ dropdownIndicator: _t,
21
+ sidebar: Lt,
22
+ agentListItemIcon: ht,
23
+ agentListContainer: ut,
24
+ agentListRetryButton: Ct
25
25
  };
26
- function Gt({
26
+ function At({
27
27
  agents: _,
28
- contentClassName: B,
28
+ contentClassName: P,
29
29
  onErrorAction: y,
30
30
  recordAction: r,
31
31
  requestState: L,
32
32
  disabled: k,
33
+ onAgentsListOpen: N,
33
34
  selectedAgent: i,
34
35
  triggerChipClassName: D,
35
- variant: P = "modal"
36
+ variant: K = "modal"
36
37
  }) {
37
38
  const {
38
39
  formatMessage: o
39
- } = rt(), [l, p] = x(!1), n = L === R.ERROR, [K, u] = x(n), N = st(), O = L === R.SUCCESS, h = L === R.IN_PROGRESS, w = o(s.selectAgent), M = o(s.defaultAgent);
40
+ } = nt(), [l, p] = B(!1), n = L === R.ERROR, [v, h] = B(n), w = lt(), O = L === R.SUCCESS, u = L === R.IN_PROGRESS, G = o(s.selectAgent), M = o(s.defaultAgent);
40
41
  let g = "";
41
- O ? g = (i == null ? void 0 : i.name) || w : n && (g = M);
42
- const G = et(null), {
43
- Wrapper: v,
44
- wrapperProps: F
45
- } = H({
46
- ref: G,
42
+ O ? g = (i == null ? void 0 : i.name) || G : n && (g = M);
43
+ const z = rt(null), {
44
+ Wrapper: F,
45
+ wrapperProps: U
46
+ } = X({
47
+ ref: z,
47
48
  textValue: g
48
49
  });
49
- at(() => {
50
+ ot(() => {
50
51
  l && r && r({
51
52
  ...E,
52
53
  action: S,
@@ -54,73 +55,75 @@ function Gt({
54
55
  });
55
56
  }, [l, r]);
56
57
  const C = f((t) => {
57
- p(!1), N({
58
- type: nt.SET_SELECTED_AGENT,
58
+ p(!1), w({
59
+ type: it.SET_SELECTED_AGENT,
59
60
  id: t.id
60
61
  }), r && r({
61
62
  ...E,
62
63
  action: S,
63
64
  target: T.SELECT_AGENT
64
65
  });
65
- }, [N, r]), U = f(() => {
66
+ }, [w, r]), j = f(() => {
66
67
  p(!1), y(), r && r({
67
68
  ...E,
68
69
  action: S,
69
70
  target: T.RETRY_LOADING_AGENTS
70
71
  });
71
- }, [y, r]), j = f((t) => {
72
+ }, [y, r]), Q = f((t) => {
72
73
  if (t.key === "Escape" && (p(!1), t.stopPropagation()), t.key === " ") {
73
74
  const A = t.target;
74
75
  if (A) {
75
- const W = A.getAttribute("data-key"), z = _.find((Y) => Y.id === W);
76
- z && C(z);
76
+ const H = A.getAttribute("data-key"), x = _.find((J) => J.id === H);
77
+ x && C(x);
77
78
  }
78
79
  }
79
- }, [_, C]), Q = f((t) => u(n && n && !l && t ? t : !1), [n, l]), b = P === "sidebar" && a.sidebar, V = (t) => {
80
+ }, [_, C]), V = f((t) => h(n && n && !l && t ? t : !1), [n, l]), W = (t) => {
81
+ t && N && N(), p(t);
82
+ }, b = K === "sidebar" && a.sidebar, Y = (t) => {
80
83
  (t.key === "ArrowUp" || t.key === "ArrowDown" || t.key === "ArrowLeft" || t.key === "ArrowRight") && t.stopPropagation();
81
84
  };
82
85
  return /* @__PURE__ */ e(c.Group, {
83
86
  className: m(a.agentSelector, D, b),
84
- name: w,
85
- onKeyDown: V,
87
+ name: G,
88
+ onKeyDown: Y,
86
89
  type: "multiple",
87
90
  children: /* @__PURE__ */ I(d.Root, {
88
91
  modal: !1,
89
- onOpenChange: p,
92
+ onOpenChange: W,
90
93
  open: l,
91
- children: [/* @__PURE__ */ e(J, {
94
+ children: [/* @__PURE__ */ e(Z, {
92
95
  content: o(s.errorTooltip),
93
- onOpenChange: Q,
94
- open: K,
96
+ onOpenChange: V,
97
+ open: v,
95
98
  side: "bottom",
96
99
  variant: "error",
97
100
  children: /* @__PURE__ */ e(d.Trigger, {
98
- disabled: k || h,
101
+ disabled: k || u,
99
102
  children: /* @__PURE__ */ I(c.TriggerChip, {
100
103
  className: a.triggerChip,
101
104
  "data-target-id": "FilterChip.TriggerChip-agentSelectorTrigger",
102
105
  value: "trigger-chip",
103
- children: [/* @__PURE__ */ e(X, {
106
+ children: [/* @__PURE__ */ e($, {
104
107
  className: a.agentStatus,
105
108
  colorIndex: 0,
106
109
  text: o(s.agent)
107
- }), h && /* @__PURE__ */ e(Z, {
110
+ }), u && /* @__PURE__ */ e(q, {
108
111
  "aria-label": o(s.loadingMessage),
109
112
  className: a.agentLoader,
110
113
  variant: "default"
111
- }), n && /* @__PURE__ */ e(tt, {
114
+ }), n && /* @__PURE__ */ e(at, {
112
115
  className: a.agentError,
113
116
  height: "1rem",
114
117
  role: "presentation",
115
118
  width: "1rem"
116
- }), /* @__PURE__ */ e(v, {
117
- ...F,
119
+ }), /* @__PURE__ */ e(F, {
120
+ ...U,
118
121
  children: /* @__PURE__ */ e(c.Label, {
119
- ref: G,
122
+ ref: z,
120
123
  className: a.agentLabel,
121
124
  children: g
122
125
  })
123
- }), !h && /* @__PURE__ */ e("div", {
126
+ }), !u && /* @__PURE__ */ e("div", {
124
127
  className: a.dropdownIndicator,
125
128
  children: /* @__PURE__ */ e(c.DropdownIndicator, {})
126
129
  })]
@@ -129,19 +132,19 @@ function Gt({
129
132
  }), /* @__PURE__ */ e(d.ContentContainer, {
130
133
  align: "start",
131
134
  className: m(a.agentListContainer, b),
132
- onKeyDownCapture: j,
135
+ onKeyDownCapture: Q,
133
136
  children: /* @__PURE__ */ I(d.MainContent, {
134
- children: [O && /* @__PURE__ */ e($, {
137
+ children: [O && /* @__PURE__ */ e(tt, {
135
138
  "aria-label": o(s.agentList),
136
- className: m([a.agentList, B]),
139
+ className: m([a.agentList, P]),
137
140
  selectedKeys: [(i == null ? void 0 : i.id) || ""],
138
- children: _.map((t) => /* @__PURE__ */ e(ot, {
141
+ children: _.map((t) => /* @__PURE__ */ e(st, {
139
142
  agent: t,
140
143
  onAction: () => C(t)
141
144
  }, t.id))
142
- }), n && /* @__PURE__ */ e(q, {
145
+ }), n && /* @__PURE__ */ e(et, {
143
146
  className: m(a.agentListRetryButton, b),
144
- onClick: U,
147
+ onClick: j,
145
148
  variant: "tertiary",
146
149
  "data-target-id": "Button-errorMessage",
147
150
  children: o(s.errorMessage)
@@ -152,6 +155,6 @@ function Gt({
152
155
  });
153
156
  }
154
157
  export {
155
- Gt as BoxAiAgentSelector,
156
- Gt as default
158
+ At as BoxAiAgentSelector,
159
+ At as default
157
160
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/box-ai-agent-selector",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "peerDependencies": {
6
6
  "@box/blueprint-web": "^7.31.1",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "@box/babel-plugin-target-attributes": "1.3.0",
14
- "@box/blueprint-web": "^9.18.8",
14
+ "@box/blueprint-web": "^9.18.9",
15
15
  "@box/blueprint-web-assets": "^4.35.0",
16
16
  "@box/eslint-plugin-blueprint": "^1.0.3",
17
17
  "@box/storybook-utils": "^0.8.3",
@@ -47,5 +47,5 @@
47
47
  "sideEffects": [
48
48
  "**/*.css"
49
49
  ],
50
- "gitHead": "19ac5dc692790cdb80e55f129c4aa8e8a4583e95"
50
+ "gitHead": "ec2e8664d2c77d849940a92b113f099ef18dd829"
51
51
  }
@@ -1,3 +1,3 @@
1
1
  import { BoxAiAgentSelectorWithApiProps } from './types';
2
- export declare function BoxAiAgentSelectorWithApi({ fetcher, hostAppName, onSelectAgent, recordAction, requestState: requestStateProp, disabled, shouldHideAgentSelectorOnLoad, triggerChipClassName, contentClassName, variant, }: BoxAiAgentSelectorWithApiProps): import("react/jsx-runtime").JSX.Element | null;
2
+ export declare function BoxAiAgentSelectorWithApi({ fetcher, hostAppName, onSelectAgent, recordAction, requestState: requestStateProp, disabled, onAgentsListOpen, shouldHideAgentSelectorOnLoad, triggerChipClassName, contentClassName, variant, }: BoxAiAgentSelectorWithApiProps): import("react/jsx-runtime").JSX.Element | null;
3
3
  export default BoxAiAgentSelectorWithApi;
@@ -1,3 +1,3 @@
1
1
  import { BoxAiAgentSelectorProps } from './types';
2
- export declare function BoxAiAgentSelector({ agents, contentClassName, onErrorAction, recordAction, requestState, disabled, selectedAgent, triggerChipClassName, variant, }: BoxAiAgentSelectorProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function BoxAiAgentSelector({ agents, contentClassName, onErrorAction, recordAction, requestState, disabled, onAgentsListOpen, selectedAgent, triggerChipClassName, variant, }: BoxAiAgentSelectorProps): import("react/jsx-runtime").JSX.Element;
3
3
  export default BoxAiAgentSelector;
@@ -70,6 +70,8 @@ export interface BoxAiAgentSelectorWithApiProps {
70
70
  * Renders the dropdown in disabled state.
71
71
  */
72
72
  disabled?: boolean;
73
+ /** Callback function when user opens agents list */
74
+ onAgentsListOpen?: () => void;
73
75
  /**
74
76
  * Determines whether the agent selector component should remain hidden
75
77
  * until the initial data fetch is complete.
@@ -104,6 +106,10 @@ export interface BoxAiAgentSelectorProps {
104
106
  * Renders the dropdown in disabled state.
105
107
  */
106
108
  disabled?: boolean;
109
+ /**
110
+ * Callback function triggered when agents list is opened
111
+ * */
112
+ onAgentsListOpen?: () => void;
107
113
  /**
108
114
  * The currently selected agent, or null if no agent is selected.
109
115
  */