@websolutespa/bom-llm 0.2.5 → 0.2.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @websolutespa/bom-llm
2
2
 
3
+ ## 0.2.7
4
+
5
+ ### Patch Changes
6
+
7
+ - added onMessage handler, LlmMessage
8
+
9
+ ## 0.2.6
10
+
11
+ ### Patch Changes
12
+
13
+ - a843ef5: Added minimize option
14
+
3
15
  ## 0.2.5
4
16
 
5
17
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -8129,7 +8129,7 @@ reactJsxRuntime_production_min.jsxs = q$2;
8129
8129
  }
8130
8130
  var jsxRuntimeExports = jsxRuntime.exports;
8131
8131
 
8132
- const [useLayout, LayoutContextProvider] = createGenericContext();
8132
+ const [useLayout_, LayoutContextProvider] = createGenericContext();
8133
8133
  function LayoutProvider(_ref) {
8134
8134
  let {
8135
8135
  children,
@@ -8141,6 +8141,7 @@ function LayoutProvider(_ref) {
8141
8141
  children: children
8142
8142
  });
8143
8143
  }
8144
+ const useLayout = useLayout_;
8144
8145
 
8145
8146
  function useAutosizeTextArea(textAreaRef, value) {
8146
8147
  reactExports.useEffect(() => {
@@ -19869,6 +19870,21 @@ function pushDataLayer(record) {
19869
19870
  }
19870
19871
  }
19871
19872
 
19873
+ const LLM_MINIMIZED_KEY = 'llm-minimized';
19874
+ function getPersistedMinimized() {
19875
+ try {
19876
+ return sessionStorage.getItem(LLM_MINIMIZED_KEY) === 'true';
19877
+ } catch {
19878
+ return false;
19879
+ }
19880
+ }
19881
+ function persistMinimized(minimized) {
19882
+ try {
19883
+ sessionStorage.setItem(LLM_MINIMIZED_KEY, String(minimized));
19884
+ } catch {
19885
+ // error
19886
+ }
19887
+ }
19872
19888
  const createLlmViewStore = _ref => {
19873
19889
  let {
19874
19890
  threadId,
@@ -19899,6 +19915,7 @@ const createLlmViewStore = _ref => {
19899
19915
  fixed: false,
19900
19916
  idle: true,
19901
19917
  visible: false,
19918
+ minimized: getPersistedMinimized(),
19902
19919
  scrollable: false,
19903
19920
  direction: 0
19904
19921
  };
@@ -20024,9 +20041,11 @@ const createLlmViewStore = _ref => {
20024
20041
  },
20025
20042
  send: async (prompt, onMessage, onEnd) => {
20026
20043
  await send(prompt, () => {
20044
+ persistMinimized(false);
20027
20045
  set({
20028
20046
  skipCustomIntro: true,
20029
- opened: true
20047
+ opened: true,
20048
+ minimized: false
20030
20049
  });
20031
20050
  setTimeout(() => {
20032
20051
  }, 50);
@@ -20047,8 +20066,10 @@ const createLlmViewStore = _ref => {
20047
20066
  pushDataLayer({
20048
20067
  event: opened ? 'llm_open' : 'llm_close'
20049
20068
  });
20069
+ persistMinimized(false);
20050
20070
  return {
20051
- opened
20071
+ opened,
20072
+ minimized: false
20052
20073
  };
20053
20074
  });
20054
20075
  },
@@ -20076,6 +20097,12 @@ const createLlmViewStore = _ref => {
20076
20097
  introed
20077
20098
  }));
20078
20099
  },
20100
+ setMinimized: minimized => {
20101
+ persistMinimized(minimized);
20102
+ set(state => ({
20103
+ minimized
20104
+ }));
20105
+ },
20079
20106
  setVisible: visible => set(state => ({
20080
20107
  visible
20081
20108
  })),
@@ -32879,6 +32906,10 @@ const PageActions = _ref => {
32879
32906
  wrapper
32880
32907
  } = _ref;
32881
32908
  const label = useLabel();
32909
+ const streaming = useLlm(state => state.streaming);
32910
+ const {
32911
+ clear
32912
+ } = useLlm(state => state.actions);
32882
32913
  const {
32883
32914
  send
32884
32915
  } = useLlmView(state => state.actions);
@@ -32886,7 +32917,8 @@ const PageActions = _ref => {
32886
32917
  setWrapper
32887
32918
  } = useActions();
32888
32919
  const onAction = async action => {
32889
- const prompt = action.message || `${action.label}: ${JSON.stringify(wrapper.actions)}`;
32920
+ const prompt = action.message || action.label;
32921
+ clear();
32890
32922
  await send(prompt, response => {
32891
32923
  // console.log('PageActions.onChunk', response.chunks);
32892
32924
  }, response => {
@@ -32904,7 +32936,11 @@ const PageActions = _ref => {
32904
32936
  }), wrapper.actions.map(x => /*#__PURE__*/jsxRuntimeExports.jsxs("button", {
32905
32937
  type: "button",
32906
32938
  className: getClassNames(style$h.action),
32907
- onClick: () => onAction(x),
32939
+ disabled: streaming,
32940
+ onClick: e => {
32941
+ e.stopPropagation();
32942
+ onAction(x);
32943
+ },
32908
32944
  children: [/*#__PURE__*/jsxRuntimeExports.jsx(ActionIcon, {
32909
32945
  action: x
32910
32946
  }), /*#__PURE__*/jsxRuntimeExports.jsx("span", {
@@ -40819,6 +40855,9 @@ const PageHistory = _ref => {
40819
40855
  removeHistory
40820
40856
  } = useLlm(state => state.actions);
40821
40857
  // console.log('item', item);
40858
+ if (!item.user) {
40859
+ return;
40860
+ }
40822
40861
  return /*#__PURE__*/jsxRuntimeExports.jsxs("div", {
40823
40862
  className: getClassNames(style$e.history),
40824
40863
  onClick: () => setHistory(item),
@@ -41336,7 +41375,11 @@ styleInject(css_248z$5);
41336
41375
  const PageSubmit = () => {
41337
41376
  const label = useLabel();
41338
41377
  useLlm(state => state.components);
41378
+ const streaming = useLlm(state => state.streaming);
41339
41379
  const prompt = useLlm(state => state.prompt);
41380
+ const {
41381
+ clear
41382
+ } = useLlm(state => state.actions);
41340
41383
  const {
41341
41384
  send
41342
41385
  } = useLlmView(state => state.actions);
@@ -41345,6 +41388,7 @@ const PageSubmit = () => {
41345
41388
  if (!prompt) {
41346
41389
  return;
41347
41390
  }
41391
+ clear();
41348
41392
  await send(prompt, response => {
41349
41393
  // console.log('PagePrompt.onChunk', response.chunks);
41350
41394
  }, response => {
@@ -41354,7 +41398,7 @@ const PageSubmit = () => {
41354
41398
  return /*#__PURE__*/jsxRuntimeExports.jsx("button", {
41355
41399
  type: "submit",
41356
41400
  className: getClassNames(style$5.submit),
41357
- "aria-disabled": !prompt,
41401
+ disabled: !prompt || streaming,
41358
41402
  "aria-label": label('llm.sendPrompt'),
41359
41403
  onClick: onSubmit,
41360
41404
  children: /*#__PURE__*/jsxRuntimeExports.jsx(IconLlmArrowUp, {})
@@ -41399,7 +41443,8 @@ const PageTextarea = () => {
41399
41443
  const prompt = useLlm(state => state.prompt);
41400
41444
  const streaming = useLlm(state => state.streaming);
41401
41445
  const {
41402
- setPrompt
41446
+ setPrompt,
41447
+ clear
41403
41448
  } = useLlm(state => state.actions);
41404
41449
  const {
41405
41450
  send
@@ -41410,6 +41455,7 @@ const PageTextarea = () => {
41410
41455
  if (!prompt) {
41411
41456
  return;
41412
41457
  }
41458
+ clear();
41413
41459
  await send(prompt, response => {
41414
41460
  // console.log('PagePrompt.onChunk', response.chunks);
41415
41461
  }, response => {
@@ -41421,7 +41467,7 @@ const PageTextarea = () => {
41421
41467
  setPrompt(prompt);
41422
41468
  };
41423
41469
  const onKeyDown = event => {
41424
- if (event.code == 'Enter' && !event.shiftKey) {
41470
+ if (event.code == 'Enter' && !event.shiftKey && !streaming) {
41425
41471
  onSubmit(event);
41426
41472
  }
41427
41473
  };
@@ -42210,6 +42256,32 @@ const Thread = () => {
42210
42256
  });
42211
42257
  };
42212
42258
 
42259
+ const MinimizeButton = _ref => {
42260
+ let {
42261
+ onClick,
42262
+ label
42263
+ } = _ref;
42264
+ return /*#__PURE__*/jsxRuntimeExports.jsx("button", {
42265
+ type: "button",
42266
+ className: "llm__trigger-minimize",
42267
+ onClick: onClick,
42268
+ "aria-label": label,
42269
+ children: /*#__PURE__*/jsxRuntimeExports.jsx("svg", {
42270
+ width: "16",
42271
+ height: "16",
42272
+ viewBox: "0 0 16 16",
42273
+ fill: "none",
42274
+ xmlns: "http://www.w3.org/2000/svg",
42275
+ children: /*#__PURE__*/jsxRuntimeExports.jsx("path", {
42276
+ d: "M4 6L8 10L12 6",
42277
+ stroke: "currentColor",
42278
+ strokeWidth: "1.5",
42279
+ strokeLinecap: "round",
42280
+ strokeLinejoin: "round"
42281
+ })
42282
+ })
42283
+ });
42284
+ };
42213
42285
  const Trigger = () => {
42214
42286
  const theme = useLlm(state => state.theme);
42215
42287
  const {
@@ -42217,16 +42289,21 @@ const Trigger = () => {
42217
42289
  } = useLlm(state => state.components);
42218
42290
  const app = useLlm(state => state.app);
42219
42291
  const opened = useLlmView(state => state.opened);
42292
+ const minimized = useLlmView(state => state.minimized);
42220
42293
  const {
42221
- open
42294
+ open,
42295
+ setMinimized
42222
42296
  } = useLlmView(state => state.actions);
42223
42297
  const label = useLabel();
42298
+ const enableMinimize = app?.contents.enableMinimize;
42224
42299
  const collapsedWelcomeText = messageMapper(app?.contents.collapsedWelcomeText);
42225
42300
  const collapsedWelcomeTextCta = messageMapper(app?.contents.collapsedWelcomeTextCta);
42226
42301
  const collapsedWelcomeTextHover = messageMapper(app?.contents.collapsedWelcomeTextHover);
42227
42302
  const position = theme.trigger?.position || 'bottom';
42228
42303
  return /*#__PURE__*/jsxRuntimeExports.jsxs(motion.nav, {
42229
- className: getClassNames('llm__trigger', '-' + position),
42304
+ className: getClassNames('llm__trigger', '-' + position, {
42305
+ '-minimized': minimized
42306
+ }),
42230
42307
  initial: {
42231
42308
  y: '200%',
42232
42309
  opacity: 0
@@ -42240,7 +42317,7 @@ const Trigger = () => {
42240
42317
  opacity: 0
42241
42318
  },
42242
42319
  transition: {
42243
- duration: .4
42320
+ duration: 0.4
42244
42321
  },
42245
42322
  "aria-label": "Trigger"
42246
42323
  /*
@@ -42256,14 +42333,20 @@ const Trigger = () => {
42256
42333
  children: [/*#__PURE__*/jsxRuntimeExports.jsx(Blob, {}), /*#__PURE__*/jsxRuntimeExports.jsx("span", {
42257
42334
  children: label('llm.button')
42258
42335
  })]
42259
- }), !opened && (collapsedWelcomeText || collapsedWelcomeTextCta || collapsedWelcomeTextHover) && /*#__PURE__*/jsxRuntimeExports.jsxs("div", {
42336
+ }), !opened && !minimized && (collapsedWelcomeText || collapsedWelcomeTextCta || collapsedWelcomeTextHover) && /*#__PURE__*/jsxRuntimeExports.jsxs("div", {
42260
42337
  className: "llm__trigger-popup -llm-t-body2",
42261
42338
  children: [(collapsedWelcomeText || collapsedWelcomeTextCta) && /*#__PURE__*/jsxRuntimeExports.jsxs(motion.div, {
42262
42339
  className: "llm__trigger-message",
42263
42340
  exit: {
42264
42341
  opacity: 0
42265
42342
  },
42266
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Canvas, {}), collapsedWelcomeText, collapsedWelcomeTextCta && /*#__PURE__*/jsxRuntimeExports.jsx("button", {
42343
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(Canvas, {}), collapsedWelcomeText, enableMinimize && /*#__PURE__*/jsxRuntimeExports.jsx(MinimizeButton, {
42344
+ onClick: e => {
42345
+ e.stopPropagation();
42346
+ setMinimized(true);
42347
+ },
42348
+ label: label('llm.minimize') || 'Minimize'
42349
+ }), collapsedWelcomeTextCta && /*#__PURE__*/jsxRuntimeExports.jsx("button", {
42267
42350
  type: "button",
42268
42351
  className: "llm__trigger-cta",
42269
42352
  children: collapsedWelcomeTextCta
@@ -45239,6 +45322,7 @@ const createLlmStore = config => {
45239
45322
  decorateUrl,
45240
45323
  label,
45241
45324
  onAction,
45325
+ onMessage,
45242
45326
  ...options
45243
45327
  } = sanitizedConfig;
45244
45328
  const theme = getThemes([customTheme], config.defaultTheme);
@@ -45478,6 +45562,7 @@ const createLlmStore = config => {
45478
45562
  if (typeof onMessage === 'function') {
45479
45563
  onMessage(response);
45480
45564
  }
45565
+ state.actions.onMessage(response);
45481
45566
  },
45482
45567
  // onEnd
45483
45568
  response => {
@@ -45779,6 +45864,12 @@ const createLlmStore = config => {
45779
45864
  }
45780
45865
  return;
45781
45866
  },
45867
+ onMessage: async message => {
45868
+ if (typeof onMessage === 'function') {
45869
+ return await onMessage(message);
45870
+ }
45871
+ return;
45872
+ },
45782
45873
  clear: () => {
45783
45874
  const {
45784
45875
  abort
@@ -46390,6 +46481,13 @@ const App = _ref => {
46390
46481
  id: data.market,
46391
46482
  title: data.market
46392
46483
  }],
46484
+ app: {
46485
+ id: 'app',
46486
+ brand: {
46487
+ name: 'Mixer',
46488
+ social: []
46489
+ }
46490
+ },
46393
46491
  menu: {},
46394
46492
  topLevelHrefs: {},
46395
46493
  topLevelRoutes: {}