bstp-agent-widget 0.2.119 → 0.2.121

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/angular.mjs CHANGED
@@ -46215,30 +46215,26 @@ function VM({ onClick: e, zIndex: t, position: n, label: r }) {
46215
46215
  return /* @__PURE__ */ (0, U.jsx)("div", {
46216
46216
  className: BM.root,
46217
46217
  style: d,
46218
- children: /* @__PURE__ */ (0, U.jsx)(dy, {
46219
- label: "Open agent widget",
46220
- position: "left",
46221
- children: /* @__PURE__ */ (0, U.jsx)(jm, {
46222
- onClick: e,
46223
- onPointerDown: a,
46224
- style: f,
46225
- classNames: {
46226
- root: BM.button,
46227
- inner: BM.buttonInner,
46228
- section: BM.iconSection,
46229
- label: BM.label
46230
- },
46231
- leftSection: /* @__PURE__ */ (0, U.jsx)(zM, {
46232
- width: s,
46233
- height: s
46234
- }),
46235
- radius: 20,
46236
- variant: "filled",
46237
- color: "accent",
46238
- "aria-label": `Open ${r ?? "agent widget"}`,
46239
- title: r ?? "Assistant",
46240
- children: r ?? "Assistant"
46241
- })
46218
+ children: /* @__PURE__ */ (0, U.jsx)(jm, {
46219
+ onClick: e,
46220
+ onPointerDown: a,
46221
+ style: f,
46222
+ classNames: {
46223
+ root: BM.button,
46224
+ inner: BM.buttonInner,
46225
+ section: BM.iconSection,
46226
+ label: BM.label
46227
+ },
46228
+ leftSection: /* @__PURE__ */ (0, U.jsx)(zM, {
46229
+ width: s,
46230
+ height: s
46231
+ }),
46232
+ radius: 20,
46233
+ variant: "filled",
46234
+ color: "accent",
46235
+ "aria-label": `Open ${r ?? "agent widget"}`,
46236
+ title: `Open ${r ?? "agent widget"}`,
46237
+ children: r ?? "Assistant"
46242
46238
  })
46243
46239
  });
46244
46240
  }
@@ -54980,17 +54976,28 @@ function fU({ visible: e, onClose: t, messages: n, composerText: r, onComposerTe
54980
54976
  }) : null;
54981
54977
  }
54982
54978
  //#endregion
54983
- //#region package/src/internal/mappers/genai-agent-catalog.mapper.ts
54979
+ //#region package/src/internal/hooks/useResolvedAgentType.ts
54984
54980
  function pU(e) {
54985
- return typeof e == "object" && !!e;
54981
+ return (0, H.useMemo)(() => {
54982
+ let t = e === "MULTI" ? "MULTI" : "SINGLE";
54983
+ return {
54984
+ agentType: t,
54985
+ isMultiAgent: t === "MULTI"
54986
+ };
54987
+ }, [e]);
54986
54988
  }
54989
+ //#endregion
54990
+ //#region package/src/internal/mappers/genai-agent-catalog.mapper.ts
54987
54991
  function mU(e) {
54992
+ return typeof e == "object" && !!e;
54993
+ }
54994
+ function hU(e) {
54988
54995
  let t = Number(e);
54989
54996
  return Number.isFinite(t) && t > 0 ? t : null;
54990
54997
  }
54991
- function hU(e) {
54992
- if (Array.isArray(e)) return e.filter(pU);
54993
- if (!pU(e)) return [];
54998
+ function gU(e) {
54999
+ if (Array.isArray(e)) return e.filter(mU);
55000
+ if (!mU(e)) return [];
54994
55001
  for (let t of [
54995
55002
  "data",
54996
55003
  "items",
@@ -55001,20 +55008,20 @@ function hU(e) {
55001
55008
  "response"
55002
55009
  ]) {
55003
55010
  let n = e[t];
55004
- if (Array.isArray(n)) return n.filter(pU);
55005
- if (pU(n)) {
55006
- let e = hU(n);
55011
+ if (Array.isArray(n)) return n.filter(mU);
55012
+ if (mU(n)) {
55013
+ let e = gU(n);
55007
55014
  if (e.length > 0) return e;
55008
55015
  }
55009
55016
  }
55010
55017
  for (let t of Object.values(e)) if (Array.isArray(t)) {
55011
- let e = t.filter(pU);
55018
+ let e = t.filter(mU);
55012
55019
  if (e.length > 0) return e;
55013
55020
  }
55014
55021
  return [];
55015
55022
  }
55016
- function gU(e) {
55017
- let t = mU(e.assistantId ?? e.assistant_id ?? e.id ?? e.agentId ?? e.agent_id ?? e.appId ?? e.app_id);
55023
+ function _U(e) {
55024
+ let t = hU(e.assistantId ?? e.assistant_id ?? e.id ?? e.agentId ?? e.agent_id ?? e.appId ?? e.app_id);
55018
55025
  if (!t) return null;
55019
55026
  let n = e.description ?? e.appDescription ?? e.app_description ?? e.label ?? e.name ?? e.assistantName ?? e.assistant_name ?? e.agentName ?? e.agent_name ?? e.title, r = typeof n == "string" && n.trim().length > 0 ? n.trim() : `Agent ${t}`, i = e.assistantKey ?? e.assistant_key ?? e.key ?? e.agentKey ?? e.agent_key ?? e.code, a = typeof i == "string" && i.trim().length > 0 ? i.trim() : r.toLowerCase().replace(/\s+/g, "-"), o = e.initialMessage ?? e.initial_message ?? e.welcomeMessage ?? e.welcome_message, s = typeof o == "string" && o.trim().length > 0 ? o.trim() : void 0;
55020
55027
  return {
@@ -55024,8 +55031,8 @@ function gU(e) {
55024
55031
  ...s ? { initialMessage: s } : {}
55025
55032
  };
55026
55033
  }
55027
- function _U(e) {
55028
- let t = mU(e.appId ?? e.app_id ?? e.id ?? e.assistantId ?? e.assistant_id);
55034
+ function vU(e) {
55035
+ let t = hU(e.appId ?? e.app_id ?? e.id ?? e.assistantId ?? e.assistant_id);
55029
55036
  if (!t) return null;
55030
55037
  let n = e.description ?? e.name ?? e.label ?? e.title ?? e.appName ?? e.app_name, r = typeof n == "string" && n.trim().length > 0 ? n.trim() : `Agent ${t}`, i = e.assistantKey ?? e.assistant_key ?? e.key ?? e.code, a = typeof i == "string" && i.trim().length > 0 ? i.trim() : r.toLowerCase().replace(/\s+/g, "-"), o = e.initialMessage ?? e.initial_message ?? e.welcomeMessage ?? e.welcome_message, s = typeof o == "string" && o.trim().length > 0 ? o.trim() : void 0;
55031
55038
  return {
@@ -55035,25 +55042,25 @@ function _U(e) {
55035
55042
  ...s ? { initialMessage: s } : {}
55036
55043
  };
55037
55044
  }
55038
- function vU(e) {
55045
+ function yU(e) {
55039
55046
  if (Array.isArray(e.apps) && e.apps.length > 0) {
55040
- let t = e.apps.map((e) => _U(e)).filter((e) => e !== null);
55047
+ let t = e.apps.map((e) => vU(e)).filter((e) => e !== null);
55041
55048
  if (t.length > 0) return t;
55042
55049
  }
55043
- let t = gU(e);
55050
+ let t = _U(e);
55044
55051
  return t ? [t] : [];
55045
55052
  }
55046
- function yU(e) {
55047
- return hU(e).flatMap((e) => vU(e));
55053
+ function bU(e) {
55054
+ return gU(e).flatMap((e) => yU(e));
55048
55055
  }
55049
55056
  //#endregion
55050
55057
  //#region package/src/internal/stores/agent-chat/agent-chat.store.ts
55051
- var bU = { runtimeInfo: {
55058
+ var xU = { runtimeInfo: {
55052
55059
  customerId: null,
55053
55060
  hasCustomerToken: !1,
55054
55061
  hasGenaiToken: !1
55055
- } }, xU = fE((e) => ({
55056
- ...bU,
55062
+ } }, SU = fE((e) => ({
55063
+ ...xU,
55057
55064
  setRuntimeInfo: (t) => e({ runtimeInfo: t }),
55058
55065
  updateCustomerId: (t) => e((e) => ({ runtimeInfo: {
55059
55066
  ...e.runtimeInfo,
@@ -55067,11 +55074,11 @@ var bU = { runtimeInfo: {
55067
55074
  ...e.runtimeInfo,
55068
55075
  hasGenaiToken: t
55069
55076
  } })),
55070
- resetRuntimeInfo: () => e({ runtimeInfo: bU.runtimeInfo })
55077
+ resetRuntimeInfo: () => e({ runtimeInfo: xU.runtimeInfo })
55071
55078
  }));
55072
55079
  //#endregion
55073
55080
  //#region package/src/internal/api/genai.service.ts
55074
- async function SU(e, t) {
55081
+ async function CU(e, t) {
55075
55082
  try {
55076
55083
  let n = new URLSearchParams();
55077
55084
  n.set("username", atob(e)), n.set("password", atob(t));
@@ -55084,7 +55091,7 @@ async function SU(e, t) {
55084
55091
  throw e;
55085
55092
  }
55086
55093
  }
55087
- async function CU(e, t) {
55094
+ async function wU(e, t) {
55088
55095
  try {
55089
55096
  let n = await EE.post("/tenants/switch", { tenant_id: e }, {
55090
55097
  anonymous: !0,
@@ -55095,21 +55102,21 @@ async function CU(e, t) {
55095
55102
  throw e;
55096
55103
  }
55097
55104
  }
55098
- async function wU(e) {
55105
+ async function TU(e) {
55099
55106
  try {
55100
55107
  return (await EE.post("/agent-message", e, { anonymous: !0 })).data;
55101
55108
  } catch (e) {
55102
55109
  throw e;
55103
55110
  }
55104
55111
  }
55105
- async function TU(e) {
55112
+ async function EU(e) {
55106
55113
  try {
55107
55114
  return (await EE.post("/agentic-app-chat", e, { anonymous: !0 })).data;
55108
55115
  } catch (e) {
55109
55116
  throw e;
55110
55117
  }
55111
55118
  }
55112
- async function EU(e) {
55119
+ async function DU(e) {
55113
55120
  let { customerToken: t, tenantId: n, ...r } = e;
55114
55121
  try {
55115
55122
  return (await EE.post("/assistant", r, {
@@ -55123,7 +55130,7 @@ async function EU(e) {
55123
55130
  throw e;
55124
55131
  }
55125
55132
  }
55126
- async function DU(e) {
55133
+ async function OU(e) {
55127
55134
  let { customerToken: t, tenantId: n, ...r } = e;
55128
55135
  try {
55129
55136
  return (await EE.post("/fetch-agentic-app", r, {
@@ -55137,17 +55144,17 @@ async function DU(e) {
55137
55144
  throw e;
55138
55145
  }
55139
55146
  }
55140
- var OU = {
55141
- loginToGenai: SU,
55142
- switchTenant: CU,
55143
- sendAgentMessage: wU,
55144
- sendAgenticAppChat: TU,
55145
- fetchAssistants: EU,
55146
- fetchAgenticApps: DU
55147
+ var kU = {
55148
+ loginToGenai: CU,
55149
+ switchTenant: wU,
55150
+ sendAgentMessage: TU,
55151
+ sendAgenticAppChat: EU,
55152
+ fetchAssistants: DU,
55153
+ fetchAgenticApps: OU
55147
55154
  };
55148
55155
  //#endregion
55149
55156
  //#region package/src/internal/queries/utils/createApiMutation.ts
55150
- function kU({ mutationKey: e, mutationFn: t, defaultOptions: n = {} }) {
55157
+ function AU({ mutationKey: e, mutationFn: t, defaultOptions: n = {} }) {
55151
55158
  return function(r) {
55152
55159
  return tS({
55153
55160
  ...n,
@@ -55163,121 +55170,115 @@ function kU({ mutationKey: e, mutationFn: t, defaultOptions: n = {} }) {
55163
55170
  }
55164
55171
  //#endregion
55165
55172
  //#region package/src/internal/queries/genai/useFetchAgenticAppsMutation.ts
55166
- var AU = kU({
55173
+ var jU = AU({
55167
55174
  mutationKey: ["genai", "agentic-apps"],
55168
- mutationFn: async (e) => OU.fetchAgenticApps(e)
55169
- }), jU = kU({
55175
+ mutationFn: async (e) => kU.fetchAgenticApps(e)
55176
+ }), MU = AU({
55170
55177
  mutationKey: ["genai", "assistants"],
55171
- mutationFn: async (e) => OU.fetchAssistants(e)
55178
+ mutationFn: async (e) => kU.fetchAssistants(e)
55172
55179
  });
55173
55180
  //#endregion
55174
- //#region package/src/internal/hooks/useAgentConfig.ts
55175
- function MU(e) {
55176
- return e === "MULTI" ? "MULTI" : "SINGLE";
55177
- }
55181
+ //#region package/src/internal/hooks/useRemoteAssistants.ts
55178
55182
  function NU(e, t) {
55179
- if (e) {
55180
- let n = t.find((t) => t.assistantId === e);
55181
- if (n) return n.assistantId;
55182
- }
55183
- return t[0]?.assistantId;
55183
+ return e && t.includes(e) ? e : t[0];
55184
55184
  }
55185
- function PU() {
55186
- let e = (0, H.useContext)(kM), { mutateAsync: t } = jU(), { mutateAsync: n } = AU(), [r, i] = (0, H.useState)(null), a = (0, H.useRef)(null), o = (0, H.useRef)(null), s = _T(), c = yT(), l = c ? Number(c) : null, u = xT();
55185
+ function PU(e, t, n) {
55186
+ let { mutateAsync: r } = MU(), { mutateAsync: i } = jU(), { isMultiAgent: a } = pU(e), [o, s] = (0, H.useState)(null), c = (0, H.useRef)(null), l = (0, H.useRef)(null), u = _T(), d = yT(), f = d ? Number(d) : null, p = xT();
55187
55187
  (0, H.useEffect)(() => {
55188
- if (!e) {
55189
- i(null);
55188
+ if (!n) {
55189
+ s(null);
55190
55190
  return;
55191
55191
  }
55192
- if (!s || !l || Number.isNaN(l) || l <= 0 || !u) {
55193
- i(null), a.current = null, o.current = null;
55192
+ if (!u || !f || Number.isNaN(f) || f <= 0 || !p) {
55193
+ s(null), c.current = null, l.current = null;
55194
55194
  return;
55195
55195
  }
55196
- let r = MU(e.agentType) === "MULTI", c = `${r ? "multi" : "single"}:${l}:${s}`;
55197
- if (a.current === c || o.current === c) return;
55198
- o.current = c;
55199
- let d = !0;
55196
+ let e = `${a ? "multi" : "single"}:${f}:${u}`;
55197
+ if (c.current === e || l.current === e) return;
55198
+ l.current = e;
55199
+ let t = !0;
55200
55200
  return (async () => {
55201
55201
  try {
55202
- let e = r ? await n({
55202
+ let n = a ? await i({
55203
55203
  page: 1,
55204
55204
  limit: 10,
55205
- customerToken: s,
55206
- tenantId: l
55207
- }) : await t({
55205
+ customerToken: u,
55206
+ tenantId: f
55207
+ }) : await r({
55208
55208
  page: 1,
55209
55209
  limit: 20,
55210
55210
  agent_type: "SINGLE",
55211
- customerToken: s,
55212
- tenantId: l
55211
+ customerToken: u,
55212
+ tenantId: f
55213
55213
  });
55214
- if (!d) return;
55215
- i(yU(e)), a.current = c;
55214
+ if (!t) return;
55215
+ s(bU(n)), c.current = e;
55216
55216
  } catch {
55217
- d && (i([]), a.current = null);
55217
+ t && (s([]), c.current = null);
55218
55218
  } finally {
55219
- o.current === c && (o.current = null);
55219
+ l.current === e && (l.current = null);
55220
55220
  }
55221
55221
  })(), () => {
55222
- d = !1;
55222
+ t = !1;
55223
55223
  };
55224
55224
  }, [
55225
- e?.agentType,
55226
55225
  n,
55226
+ i,
55227
+ r,
55228
+ u,
55229
+ f,
55230
+ a,
55231
+ p
55232
+ ]);
55233
+ let m = o ?? [], h = NU(t, m.map((e) => e.assistantId));
55234
+ return {
55235
+ availableAssistants: m,
55236
+ selectedAssistantId: h,
55237
+ selectedAssistant: m.find((e) => e.assistantId === h)
55238
+ };
55239
+ }
55240
+ //#endregion
55241
+ //#region package/src/internal/hooks/useAgentConfig.ts
55242
+ function FU() {
55243
+ let e = (0, H.useContext)(kM), { agentType: t } = pU(e?.agentType), { selectedAssistantId: n, selectedAssistant: r } = PU(e?.agentType, e?.assistantId, !!e), i = (0, H.useMemo)(() => e ? {
55244
+ ...e,
55245
+ assistantId: n,
55246
+ agentType: t,
55247
+ assistantLabel: r?.label,
55248
+ assistantInitialMessage: r?.initialMessage
55249
+ } : null, [
55250
+ e,
55227
55251
  t,
55228
- s,
55229
- l,
55230
- u
55252
+ r,
55253
+ n
55231
55254
  ]);
55232
- let d = (0, H.useMemo)(() => {
55233
- if (!e) return null;
55234
- let t = r ?? [], n = MU(e.agentType), i = NU(e.assistantId, t), a = t.find((e) => e.assistantId === i);
55235
- return {
55236
- ...e,
55237
- assistantId: i,
55238
- agentType: n,
55239
- assistantLabel: a?.label,
55240
- assistantInitialMessage: a?.initialMessage
55241
- };
55242
- }, [e, r]);
55243
- if (!d) throw Error("AgentConfigContext is missing.");
55244
- return d;
55255
+ if (!i) throw Error("AgentConfigContext is missing.");
55256
+ return i;
55245
55257
  }
55246
55258
  //#endregion
55247
55259
  //#region package/src/internal/hooks/useAgentRuntime.ts
55248
- function FU() {
55260
+ function IU() {
55249
55261
  let e = (0, H.useContext)(AM);
55250
55262
  if (!e) throw Error("AgentRuntimeContext is missing.");
55251
55263
  return e;
55252
55264
  }
55253
55265
  //#endregion
55254
55266
  //#region package/src/internal/hooks/useAgentCustomerToken.ts
55255
- function IU() {
55256
- let e = FU();
55267
+ function LU() {
55268
+ let e = IU();
55257
55269
  return (0, H.useMemo)(() => {
55258
55270
  let t = e?.customerToken;
55259
55271
  return typeof t != "string" || t.trim().length === 0 ? null : t;
55260
55272
  }, [e?.customerToken]);
55261
55273
  }
55262
55274
  //#endregion
55263
- //#region package/src/internal/hooks/useResolvedAgentType.ts
55264
- function LU(e) {
55265
- return (0, H.useMemo)(() => {
55266
- let t = e === "MULTI" ? "MULTI" : "SINGLE";
55267
- return {
55268
- agentType: t,
55269
- isMultiAgent: t === "MULTI"
55270
- };
55271
- }, [e]);
55272
- }
55273
- //#endregion
55274
55275
  //#region package/src/internal/queries/genai/useSendAgentMessageMutation.ts
55275
- var RU = kU({
55276
+ var RU = AU({
55276
55277
  mutationKey: ["genai", "agent-message"],
55277
- mutationFn: async ({ payload: e }) => OU.sendAgentMessage(e)
55278
- }), zU = kU({
55278
+ mutationFn: async ({ payload: e }) => kU.sendAgentMessage(e)
55279
+ }), zU = AU({
55279
55280
  mutationKey: ["genai", "agentic-app-chat"],
55280
- mutationFn: async ({ payload: e }) => OU.sendAgenticAppChat(e)
55281
+ mutationFn: async ({ payload: e }) => kU.sendAgenticAppChat(e)
55281
55282
  });
55282
55283
  //#endregion
55283
55284
  //#region package/src/internal/hooks/useSendChatMessage.ts
@@ -55338,7 +55339,7 @@ function qU() {
55338
55339
  return e?.randomUUID ? e.randomUUID() : `${Date.now()}-${Math.random().toString(16).slice(2)}`;
55339
55340
  }
55340
55341
  function JU() {
55341
- let e = FU(), t = IU(), n = PU(), { agentType: r, isMultiAgent: i } = LU(n.agentType), { sendChatMessage: a } = BU(), [o, s] = (0, H.useState)([]), [c, l] = (0, H.useState)(""), [u, d] = (0, H.useState)(null), [f, p] = (0, H.useState)(!1), [m, h] = (0, H.useState)(null), g = (0, H.useRef)(!1), _ = VU(n), v = i ? n.assistantLabel ?? "Assistant" : "Assistant", y = (0, H.useCallback)((e) => {
55342
+ let e = IU(), t = LU(), n = FU(), { agentType: r, isMultiAgent: i } = pU(n.agentType), { sendChatMessage: a } = BU(), [o, s] = (0, H.useState)([]), [c, l] = (0, H.useState)(""), [u, d] = (0, H.useState)(null), [f, p] = (0, H.useState)(!1), [m, h] = (0, H.useState)(null), g = (0, H.useRef)(!1), _ = VU(n), v = i ? n.assistantLabel ?? "Assistant" : "Assistant", y = (0, H.useCallback)((e) => {
55342
55343
  let t = {
55343
55344
  id: qU(),
55344
55345
  sentBy: "user",
@@ -55548,7 +55549,7 @@ function QU(e, t, n, r, i) {
55548
55549
  //#endregion
55549
55550
  //#region package/src/internal/hooks/useAgentRuntimeInfo.ts
55550
55551
  function $U() {
55551
- let e = FU(), { runtimeInfo: t, setRuntimeInfo: n } = xU(), r = (0, H.useCallback)(async () => {
55552
+ let e = IU(), { runtimeInfo: t, setRuntimeInfo: n } = SU(), r = (0, H.useCallback)(async () => {
55552
55553
  if (!e) {
55553
55554
  n({
55554
55555
  customerId: null,
@@ -55574,7 +55575,7 @@ function $U() {
55574
55575
  //#endregion
55575
55576
  //#region package/src/internal/hooks/useAgentSpeechLanguage.ts
55576
55577
  function eW() {
55577
- let e = FU();
55578
+ let e = IU();
55578
55579
  return (0, H.useMemo)(() => e && GU(e) || "en-US", [e]);
55579
55580
  }
55580
55581
  //#endregion
@@ -55739,9 +55740,9 @@ function sW(e, t = {}) {
55739
55740
  }
55740
55741
  //#endregion
55741
55742
  //#region package/src/internal/queries/genai/useGenaiLoginMutation.ts
55742
- var cW = kU({
55743
+ var cW = AU({
55743
55744
  mutationKey: ["genai", "login"],
55744
- mutationFn: async ({ serviceAccount: e, serviceKey: t }) => OU.loginToGenai(e, t)
55745
+ mutationFn: async ({ serviceAccount: e, serviceKey: t }) => kU.loginToGenai(e, t)
55745
55746
  }), lW = new gE("useGenaiLogin"), uW = null, dW = null;
55746
55747
  function fW(e = !1) {
55747
55748
  let t = (0, H.useContext)(kM), { mutateAsync: n } = cW(), [r, i] = (0, H.useState)(!1), [a, o] = (0, H.useState)(null), [s, c] = (0, H.useState)(null), [l, u] = (0, H.useState)(null);
@@ -55789,9 +55790,9 @@ function fW(e = !1) {
55789
55790
  }
55790
55791
  //#endregion
55791
55792
  //#region package/src/internal/queries/genai/useTenantSwitchMutation.ts
55792
- var pW = kU({
55793
+ var pW = AU({
55793
55794
  mutationKey: ["genai", "tenant-switch"],
55794
- mutationFn: async ({ tenant_id: e, token: t }) => OU.switchTenant(e, t)
55795
+ mutationFn: async ({ tenant_id: e, token: t }) => kU.switchTenant(e, t)
55795
55796
  }), mW = new gE("useGenaiTenantSwitch"), hW = null, gW = null;
55796
55797
  function _W(e, t, n = !1) {
55797
55798
  let { mutateAsync: r } = pW(), [i, a] = (0, H.useState)(!1), [o, s] = (0, H.useState)(null), [c, l] = (0, H.useState)(!1);